I have some DIVs with ID “div1”, “div2” … “divx”. I want to perform an operation on them. Is there any way to get the element ID .contains “div”. Any other idea?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the starts with selector
The above will grab all divs that have an
idattribute that begins with the lettersdiv.jsFiddle example that makes all divs with id
div...invisible.Here’s how to handle the trickier case if you want to match
divfollowed by a number but notdivfollowed by something else. Sodiv1would match, butdivxwould not.In this case we use filter() with a function. The function should return true for when we want a match and false for when we do not. match() and a regex is great for this (you can use
[0-9]to represent a digit in a regex or the simpler[\d]):attr() returns the value of the specified attribute, in this case
id.jsFiddle example that makes all
divfollowed by number disappear, but notdivfollowed by other things.