在我的HTML中有两个具有相同类的div.如果我想逐个删除div,它们都会被删除.我怎样才能(在使用Jquery时)逐个删除第二个div?有没有办法让它"跳过"它找到的第一个div?
代码如下所示:
<div class="wrapper">
<div class="randomdiv">
<div class="oneofthetwodivs">
</div>
</div>
<div class="randomdiv"></div>
<div class="randomdiv"></div>
<div class="oneofthetwodivs">
</div>
Run Code Online (Sandbox Code Playgroud)
dsg*_*fin 10
您可以使用eq()
该类来定位第二个元素(它基于零):
$('.oneofthetwodivs').eq(1).remove();
Run Code Online (Sandbox Code Playgroud)
这应该有效:
$(".oneofthetwodivs").eq(1).remove();
Run Code Online (Sandbox Code Playgroud)
或者
$(".oneofthetwodivs:last").remove();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11277 次 |
最近记录: |