Find the html element whose identifier begins with

my question is this:

I have HTML code on several pages, on each of them I used JQgrid (jquery grid) to display some data. I knew that on each of these pages the element containing the JQgrid is called "LIST_xxx". Now I need to make javascript that takes this “LIST_XXXX” element on each page and does some things. How could I search for an element by identifier, but only knowing its initial part (identifier, as I mentioned earlier):

$('#list_[XXXX]')... --> The part surrounded by [] is variable on each page, i want to discriminate that. 

I hope I get it. Thank.

+69
jquery
Feb 19 2018-10-19
source share
5 answers

Try

 $('div[id^="list_"]') 

He should work

+142
Feb 19 '10 at 18:48
source share

You need to use an attribute with a selector , for example:

 $('[id^=list_]').whatever() 
+21
Feb 19 '10 at 18:48
source share

Give this element a generic class name or some other attribute that you can request.

+7
Feb 19 '10 at 18:44
source share

Use the "attribute starts with" selector http://api.jquery.com/attribute-starts-with-selector/

 $("[id^=list_]") 

Keep in mind that this is inefficient. Prefix with the tag name and, if possible, descent from the nearest parent.

+5
Feb 19 '10 at 18:51
source share

To get an element ending with a specific identifier / character

 find('[id$=someid]') 

To get an element starting with a specific id / character

 find('[id*=anotherid]') 

To get an item matching a specific id / character

 find('[id^=id]') 
0
May 7 '19 at 5:47
source share



All Articles