Refresh all elements that their ids are partly equal

I have a webpage which contains while loop, i have assign an id to each element inside the while loop, here is an example:

< tagname id="show_div_1">< /tagname>

The "show_id_" is static but "1" is dynamic which comes from loop and it will be increase to 2,3,4 ...etc.

Anyone knows how to select such elements using javascript or jquery?

Or is there any alternative way to do so?

Upvotes: 0

Views: 36

Answers (3)

D4V1D
D4V1D

Reputation: 5849

Try:

$('tagname[id^="show_div_"]');

Upvotes: 2

Ed Heal
Ed Heal

Reputation: 60007

Why not just put them in the same class?

i.e.

 <tagname class="something">

then

$(.something)

Upvotes: 2

Eric Martinez
Eric Martinez

Reputation: 31787

You can use the Jquery contains selector

Like this

$('tagname[id*="show_div_"]').each(function() { 
   // ...
});

Upvotes: 1

Related Questions