Abi*_*hek 0 jquery jquery-selectors
我有以下代码片段
<div class='container'>
<a href=''>
<img alt='' class='image0' src='images/Gallery/gallery-01.jpg' title='info'/>
</a>
<a href=''>
<img alt='' class='image1' src='images/Gallery/gallery-01.jpg' title='info'/>
</a>
<a href=''>
<img alt='' class='image2' src='images/Gallery/gallery-01.jpg' title='info'/>
</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我可以用
$('.container a:first')或$('.container a:last')访问第一个和最后一个元素,但我如何访问div上的第二个锚标记?.
Aln*_*tak 10
使用:eq选择器:
$('.container a:eq(1)')
Run Code Online (Sandbox Code Playgroud)
或(最好).eq功能:
$('container a').eq(1)
Run Code Online (Sandbox Code Playgroud)