我正在尝试对 ID 不是“第一个”的所有 div 采取操作。但不知何故,当我运行每个循环时,它会忽略第一个 div 并继续执行下一个。我有一种感觉,这是一个很容易解决的问题...
jQuery:
$(document).ready(function(){
$.each($(".storyBlock:not(:first)"), function(i, object){
console.log(i); //returns 0 for the second item, 1 for the third item
});
});
HTML:
<div class="content">
<div class="storyBlock" id="second" style="margin-top:1500px" img="mypathhere"></div>
<div class="storyBlock" id="third" style="margin-top:1500px" img="mypathhere"></div>
<div class="storyBlock" id="fourth" style="margin-top:1500px" img="mypathhere"></div>
</div>
最佳答案
:first
与 #first
不同。前者是一组元素中的第一个元素,而#first
是ID属性为first
的元素,这似乎就是你想要的。
请注意,您也可以将其写为:
$(".storyBlock:not(#first)").each
关于jquery - 使用每个与不,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16922682/