[英]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. 例如,我有2个
<a>
元素。 They both have the class myClass
. 它们都具有
myClass
类。 One of the elements has rel="1"
and the other has rel="2"
. 其中一个元素具有
rel="1"
,另一个元素具有rel="2"
。 I wish to only change the z-index
on the one which has rel=1
. 我只想更改
rel=1
的z-index
。 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.
然后,您将知道它是您的选择器还是定位器。
由于z-index
包含连字符,因此在驼峰情况下必须引用它:
$(".myClass[rel='1']").css("zIndex", 10);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.