jquery for each all elements having similar id

Ashwin picture Ashwin · Apr 24, 2013 · Viewed 33.5k times · Source

I have many elements accross page - ID1, ID2 ID3 ...

I want to manipulate all the elements. Is there any simpler way to do this.

$("#ID").each(function(){ ... });

Answer

Dipesh Parmar picture Dipesh Parmar · Apr 24, 2013

You can use ^ selector.

Example

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

^= select DOM whose ID attribute starts with ID (i.e ID1, IDID,IDS,ID2 etc)