tags:

views:

41

answers:

3

I have a group of id's with similar names (ex: div1, div2, div3) that are all going to perform the same function. is there an easy way in jQuery to create an array by calling the prefix of the id ("div")?

+1  A: 

You can use this attribute selector to test the start of the ID attribute value:

[id^=div]
Gumbo
awesome, thanks!
homer
+1  A: 

You can create a filter selector that gets all divs where the id starts with "div" like this:

 $("div[id^='div']")
Vincent Ramdhanie
A: 

I suggest the id values of your divs are div1, div2, div3.

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

This doesn't work anymore:

$('div#div\\S*')
powtac