I have these 4 HTML snippets:
Siblings:
<div class="a">...</div> <div class="b">...</div> <!--selected--> <div class="b">...</div> <!--not selected-->
Wrapped 1:
<div class="a">...</div> <div> <div class="b">...</div> <!--selected--> </div> <div class="b">...</div> <!--not selected-->
Wrapped 2:
<div> <div class="a">...</div> </div> <div> <div class="b">...</div> <!--selected--> </div> <div class="b">...</div> <!--not selected-->
Separated:
<div class="a">...</div> <div>...</div> <div class="b">...</div> <!--selected--> <div>...</div> <div class="b">...</div> <!--not selected--> <div>...</div> <div class="b">...</div> <!--not selected-->
How can I, with jQuery, select the next .b
element for any given .a
element, regardless of nesting?
I want something like this:
$('.a').each(function() {
var nearestB = $(this)./*Something epically wonderful here*/;
//do other stuff here
});