A similar question was asked before, but I'm looking for a jQuery solution using only the html below (ie. no classes or id attributes):
<h2>Foo</h2>
<p>asdf</p>
<ul><li>asdf</li></ul>
<p>asdf</p>
<h2>Bar</h2>
<p>asdf</p>
<p>asdf</p>
<h2>Baz</h2>
<p>asdf</p>
<p>asdf</p>
I'd like to use some jQuery like:
$('h2').afterButBeforeNext('h2').doSomething();
This should:
- select all the sibling elements after the specified element, but before the next occurrence of the specified element.
- if there is no end element, then select all the elements underneath it.