Find html element which id starts with

Viewed 109193

my question is this:

I have HTML code in multiple pages, on each of them I used a JQgrid (jquery grid) for display some data. I knew that on each of those pages, the element that holds the JQgrid is named as "LIST_xxx". Now I need to make a javascript that takes that element "LIST_XXXX" on each page and does some stuff. How could I search for an element by ID but only knowing its initial part (of the ID ,like i mentioned previously):

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

I hope i made myself clear. Thanks.

5 Answers

Try

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

It should work

Give that element a common class name or some other attribute you can query for.

To get an element ending with a certain id/character

find('[id$=someid]')

To get an element starting with a certain id/character

find('[id*=anotherid]')

To get an element matching with a certain id/character

find('[id^=id]')
Related