Find html element which id starts with

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.


Try

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

It should work


You need to use the attribute starts with selector, like this:

$('[id^=list_]').whatever()

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


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

$("[id^=list_]")

Be aware that this is inefficient. Prefix with the tag name and descend from the nearest parent if possible.