jquery - 如何分别处理 .nextAll() 或 .prevAll() - 每个元素?

标签 jquery

我正在寻找一些东西,使我能够单独控制 .prevAll() 或 .nextAll() jQuery 方法返回的每个元素。

类似于:

<div id="home">
   <div class="box"></div>
   <div class="box"></div>
   <div class="box"></div>
   <div class="box"></div>
   <div class="box"></div>
</div>

还有类似的东西:

$('#home .box').mouseover(function(){

var hovBox = $(this);
var prevAll = hovBox.prevAll();
var nextAll = hovBox.nextAll();

     nextAll.each(function(){

           // ...and do something with each returned element
           // NOT with ALL returned elements, just handle each separately
           // through some other type of selector
     });
});

感谢您的帮助

最佳答案

$.each 允许您使用 this 访问 DOM 元素:

nextAll.each(function(index){
    // ...and do something with each returned element
    $(this).fadeTo('fast', index/5);
});

这是 fiddle : http://jsfiddle.net/2MMGw/1/

http://api.jquery.com/each/

关于jquery - 如何分别处理 .nextAll() 或 .prevAll() - 每个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6940780/

相关文章:

javascript - Angularjs 邮件应用程序的长轮询

javascript - <img> src 属性不使用 Jquery 改变

javascript - 在 Internet Explorer 中下载动态 CSV

php - 多个文档就绪函数相互覆盖

jquery - 自定义样式的 Wordpress 主题选项

javascript - 正确重命名克隆输入 JQuery

jquery - 你会如何比较 jQuery 对象?

来自 sprite 的 JQuery 菜单

javascript - 如何适应高度为 :100% on iPhone 的 DIV

jquery - 通缉 : 'Super selector' or How focus the first visible "input" field that has no value?