I have some div elements
The structure is
<div id="comment">
<div id="m1">...</div>
<div id="m2">...</div>
</div>
I want to apply some CSS or Class to the even/odd inner div of comments (or to the m1/m2 div)
So i coded this, but it did not worked 🙁
$("div>div:even").addClass("evn");
What i’m missing ?
:evenand:oddare 0-indexed, and may not produce results you’re looking for. The first element is number 0, and that’s even, so it gets selected by:even, rather than the second one.For 1-indexing, you’re missing the
:nth-child()pseudo-class:Make sure that you spelled the class name correctly too, I don’t know if your CSS defines an
.evnclass…