Get elements in jQuery where "x" attribute = "y"
How can I 开发者_如何学编程change the attribute of an element, depending on another attribute?
For example, I have 2 <a>
elements. They both have the class myClass
. One of the elements has rel="1"
and the other has rel="2"
. I wish to only change the z-index
on the one which has rel=1
. How do I do this?
I've tried:
$(".myClass[rel='1']").css("z-index", 10);
But it doesn't work. Cheers.
try this:
$(".myClass[rel='1']").css('display', 'none');
and see if it disappears. Then you will know if it is your selector, or positioning.
As z-index
contains a hyphen you have to reference it in camel case:
$(".myClass[rel='1']").css("zIndex", 10);
精彩评论