Suppose I have this HTML:
<div id="Wrapper">
<div class="MyClass">some text</div>
<div class="MyClass">some text</div>
<div class="MyBorder"></div>
<div class="MyClass">some text</div>
<div class="MyClass">some text</div>
<div class="MyClass">some text</div>
<div class="MyBorder"></div>
<div class="MyClass">some text</div>
<div class="MyClass">some text</div>
</div>
I want to get the text of the MyClass divs next to the one clicked on, in the order they’re in.
This is what I have:
$('#Wrapper').find('.MyClass').each(function () {
AddressString = AddressString + "+" + $(this).text();
});
I know adds ALL the MyClass divs; I’m just wondering if there’s a quick way to do it.
Thanks.
Using .text(), .prevUntil() and .nextUntil()
To get text of all previous and next
.MyClasselement from clicked.MyBorder:Combination of
prevUntil(),nextUntil()with siblings()