我想在each()函数中选择这个的下一个元素.查看代码注释
$(function(){ var selects = $('body').find('span'); selects.each(function(index,el){ if(index==0){ //remove the next span of this,which is span2 } }); }); <body> <div> <span>1</span> </div> <span>2</span> <div> <span>3</span> </div> </body>
解决方法
根据您的DOM结构,您可以执行以下操作:
var selects = $('body').find('span'); selects.each(function(index,el) { if(index !== selects.length - 1) { // select the next span alert(selects.eq(index + 1).text()); } });