开发者

Get elements in jQuery where "x" attribute = "y"

开发者 https://www.devze.com 2023-01-21 21:40 出处:网络
How can I 开发者_如何学编程change the attribute of an element, depending on another attribute?

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消