开发者

JQuery finding the right .next()

How can I keep going through .next()s until I find the one with the class or id I want?

.next() only searches the immediately succeeding sibling but I want JQuery to keep going until it finds the one I want and only return that one. In the below case, I'd like JQuery to return the bottom div:

$('.toggler').nextUntilOneIWant('.expand_me')

<a class="toggler"></a>

<div> so开发者_Python百科me stuff </div>
...divs...
<div class="expand_me"></div>


Try this, it will look for all the next siblings of .toggler untill it finds '.expand_me` and will give only the element where it found this match.

$('.toggler').nextAll('.expand_me:first');


$('.toggler').nextAll('.expand_me').first()
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜