Assume the following situation
<div>
<div1>
<divA>
</divA>
<divB>
</divB>
</div1>
<div2>
</div2>
</div>
I would like to target <div1>, make an addClass() on it without adding a class to its child.
I tried to use :nth-child(1) selector, or :eq() (I am using Jquery)
. But the :nth-child(1) adds the class to all the 1-children element and :eq() doesn’t fit because I want toi target <div1> from its parent element.
Could anyone help ?
Best,
Newben
A truely cross browser version too:
And if these divs don’t have classes: