简体   繁体   English

在jQuery中获取元素,其中“ x”属性=“ y”

[英]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=1z-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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM