Select all elements between two tags of the same type?

How can I select all elements between two tags of the same type using javascript or jquery?

For example, if I had:

<h1></h1> <h2><h2> <li1></li1> <li2></li3> <li3></li4> <h2></h2> 

How can I get everything <li> ?

I tried using this $units=$(this).nextuntil("h2"); but he did not work

0
source share
1 answer
 $('h2:first').nextUntil('h2:last'); 

Demo: http://www.jsfiddle.net/4yUqL/63/

This, of course, only works in this particular example. In more complex markups, you should probably be more specific. Like $('h2:eq(2)') or other pseudo selectors.

+1
source

All Articles