views:

50

answers:

2

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.

A: 

As z-index contains a hyphen you have to reference it in camel case:

$(".myClass[rel='1']").css("zIndex", 10);
ILMV
That is not true, if you set the the style via `css(attr, value)`, you can use the "normal" CSS names for the attributes. Proof: http://jsfiddle.net/WFznU/1/
Felix Kling
Balls... fair enough ;-)
ILMV
+1  A: 

try this:

$(".myClass[rel='1']").css('display', 'none');

and see if it disappears. Then you will know if it is your selector, or positioning.

Josiah Ruddell