87,994
社区成员
发帖
与我相关
我的任务
分享
Matches all elements that are the nth-child of their parent or that are the parent's even or odd children.
While :eq(index) matches only a single element, this matches more than one: One for each parent with index. Multiple for each parent with even, odd, or equation. The specified index is one-indexed, in contrast to :eq() which starts at zero.
* Demo
* View Source
Finds the second li in each matched ul and notes it.
$("ul li:nth-child(2)").append("<span> - 2nd!</span>");<ul>
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
</ul>
<ul>
<li>Glen</li>
<li>Tane</li>
<li>Ralph</li>
</ul><li>Karl</li>, <li>Tane</li>