I want to select the next element of this in each() function. check out the code comments
$(function(){
var selects = $('body').find('span');
selects.each(function(index,el){
if(index==0){
//remove the next span of this, which is sp开发者_JAVA技巧an2
}
});
});
<body>
<div>
<span>1</span>
</div>
<span>2</span>
<div>
<span>3</span>
</div>
</body>
Based on your DOM structure, you can do:
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());
}
});
You can try it here.
精彩评论