jQuery – How do you say: are there any divs called x with the property display==block?
How do you taget specific divs with specific properties in Jquery?
Thanks…
and by “called x” I mean divs with a class name of x
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.
Use the following code:
This defined variable is a JQuery object, containing references to all divs with
display:block). For instance, if you were wondering how many divs have thedisplay:blockproperty, use:alert(DivsWithDisplayBlock.length).Note: You said *
all divs called x. I assumeed that you were talking about all DIVs with the.xclass. Other possible ways to “call” your div:#id– ID. This should be uniquer, and occur only once. If you’ve defined multiple elements with IDx, I recommend to changeid=toclass=[name="x"]– Select by name.EDIT (comment)
Changing attributes:
The
.css()method will adddisplay:noneto each element which is referenced byDivsWithDisplayBlock.If you want to change multiple styles of the
DIV.xelements, I recommend to use.toggleClass("x-visible", "x-invisible"). Define the style properties in the stylesheet (.x-visible, .x-invisible). When you execute the.toggleClass(..)method on the matched elements, the class names will swap.Example: