Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find html element which id starts with

Tags:

jquery

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.

like image 948
lidermin Avatar asked Feb 19 '10 18:02

lidermin


People also ask

How do I find an element with a specific id?

getElementById() The Document method getElementById() returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.

How will you retrieve an element with the id first?

The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object. In the Console, get the element and assign it to the demoId variable. Logging demoId to the console will return our entire HTML element.

Can id start with number HTML?

For HTML 4, the answer is technically: ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").


1 Answers

Try

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

It should work

like image 94
Glen Little Avatar answered Dec 04 '22 06:12

Glen Little