jquery - 使用每个与不

标签 jquery css

我正在尝试对 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/

相关文章:

javascript - 无法复制 Jquery Mobile 自动完成演示

javascript - 变量在内部函数中不可写

jquery - 使用 CSS 和 Jquery 循环排列元素

CSS - 在固定定位元素下滚动内容?

css - div 的定位 - CSS

javascript - 如何在禁用模式下停止按钮的悬停效果

jquery - 在表单中使用 jstree 复选框

css - Outlook 2010 渲染差异?

html - html 中的链接 - 颜色

HTML:使容器居中