使用选择器访问jquery对象

问题描述:

我有一个无序列表,其中包含几个div。每个列表项都使用jquery创建并放入一个变量中。使用选择器访问jquery对象

我需要一种方法来选择jquery对象内每个div的nth-child(偶数)。

ele = myList.append("<li> \ 
<div class='name'>"+this.name+"</div> \ 
<div class='test'>test</div> \ 
</li>"); 

我该如何使用jquery对象中的变量“ele”来获取包含在其中的第n个子元素?

我想象的,这不工作:

$(ele+" div:nth-child(even)").addClass("my-class"); 

另一件事我想象

ele.children("div:nth-child(even)").addClass('my-class')); 

而且似乎不工作。

使用.find()

ele.find("div:nth-child(even)").addClass('my-class'); 

crazy demo