i have some dynamic code that will make a list of divs. i want to get back a list of items to loop through that have an id with the same start of the string.
For example, i might have
<div id="table1" . . .
<div id="table2" . . .
<div id="table3" . . .
how, using jquery, can i get a list of all divs that have an id that starts with “table” ?
You can use an attribute selector for this.
The above means find all divs with an id that starts with “table”.
Generally you want to avoid attribute selectors where possible however so if this is going to be something you do a lot I’d suggest changing your HTML:
So you can simply do:
which will be much faster.
Update: You seem to have asked (in comments) regarding looping. For this use
each():