Get the next div in the doc after the current one with the same class
On click of the current div i want the very next div with the same class name in the entire document. Document is having a very complex nested structure.
<div><div><div class='1'></div></div></div>
<div><div class='1'></div></div>
<div><div><div><div><开发者_开发百科div class='1'></div></div></div></div></div>
Assuming that the elements are not siblings, you could do something like this:
var $elements = $('.someClass');
$elements.click(function() {
var $nextElement = $elements.eq($elements.index(this) + 1);
});
Reference: eq
, index
DEMO
jQuery('currentDiv .className').click(function(){
var target = jQuery(this).next('.className');
});
精彩评论