0

I have a group of IDs 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
  • the answer to that depends on the nature of those ids. Are they dynamically generated or static? Commented Oct 19, 2009 at 17:03

3 Answers 3

1

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

[id^=div]
Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

0

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

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

This doesn't work anymore:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.