开发者

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');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜