Question: I am trying to search all input elements that starts with a partcular set of characters such as 'idAcc' where my VF page has two inputfields with id = idAccFN and id= idAccLN respectively.

```
 <apex:inputField id="idAccFN" value="{!cr.FirstName__c}" />
 <apex:inputField id="idAccLN" value="{!cr.LastName__c}" />

```

I'm using the below JQuery syntax but thats working partially ... Explained in 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 
});

```

Answer: 
the Id you 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.
});

```
If you inspect the elements on the page you will notice that the id's are actually prepended by VF with j\_id0 etc (`j_id0:j_id1:page:messageDetail`)if you do not place IDs on all parent elements in your vf page. Thus the ID's do not start with the `idAcc` that you expect.

If you need the 'Starts With' then you could look at `$Component` in javascript:

> 
> Use the $Component global variable to simplify referencing the DOM ID
>  that is generated for a Visualforce component, and reduce some of the
>  dependency on the overall page structure.
> 
> 
> 

<https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_access.htm>