2014-12-02 27 views
0

你如何循環每個元素之前,每個元素之後單擊元素?jQuery每一個nextAll prevAll

這工作

$(".bar").bind('click',function(e){ 
    e.preventDefault(); 
    $(this).each(function(i,o) { 
     $(o).css('z-index',i); 
    }); 
}); 

但這

$(".bar").bind('click',function(e){ 
    e.preventDefault(); 
    $(this).nextAll.each(function(i,o) { 
     $(o).css('z-index',i); 
    }); 
}); 

回報Uncaught TypeError: undefined is not a function

+0

你'nextAll'應的概率是'nextAll()' – Tomanow 2014-12-02 21:13:08

+0

試試這個:'$(本).nextAll()各(...);' – 2014-12-02 21:19:34

回答

1

nextAll是需要執行的功能,而不是您要訪問的屬性。需求是這樣的:

$(this).nextAll().each(function(i,o){...}); 
+0

感謝。隨着這一點,我終於得到了我的佈局工作。 http://codepen.io/dcdev/full/azvGwm/ – davidcondrey 2014-12-03 01:21:39