How to find jquery get all elements id starts with or ends with in visual force?

782    Asked by AashnaSaito in Salesforce , Asked on Sep 22, 2022

I am trying to search all input elements that start with a particular set of characters such as 'idAcc' where my VF page has two input fields with id = idAccFN and id= idAccLN respectively.


 
 

I'm using the below JQuery syntax but that's working partially ... Explained in the comments below .. Kindly help.


 var j$ = jQuery.noConflict();
 j$(document).ready(function(){
    jQuery( 'input[id$=Name]' ).val('Foo');  // ID ending with Name working 
    jQuery( 'input[id^=idAcc]' ).val('Apu')  //Id starting with idAcc not working 
});


Answered by Amit verma

Regarding the jquery get all elements Id starts with or ends with visualforce, your set gets prepended by VF, so you need to do a "contains" selector. And if you want each element on the page, you need to use a ".each", like this:


j$(document).ready(function(){
jQuery( 'input[id*=Name]' ).each(function(el){
  el.val('Foo'); // do something with the input here.
});

Your Answer

Interviews

Parent Categories