I have an unordered list with several divs contained inside. Each list item is created with jquery and put into a variable.
I need a way to select the :nth-child(even) of each div within the jquery object.
ele = myList.append("<li> \
<div class='name'>"+this.name+"</div> \
<div class='test'>test</div> \
</li>");
How would I use the variable "ele" within a jqu开发者_C百科ery object to get the nth-child contained within?
What I had imagined, which doesn't work:
$(ele+" div:nth-child(even)").addClass("my-class");
Another thing I imagined
ele.children("div:nth-child(even)").addClass('my-class'));
Also doesn't seem to work.
use .find()
ele.find("div:nth-child(even)").addClass('my-class');
精彩评论