开发者

Select all elements in between two tags of the same type?

开发者 https://www.devze.com 2023-02-05 02:37 出处:网络
How could i开发者_开发百科 select all the elements between two tags of the same type using javascript or jquery?

How could i开发者_开发百科 select all the elements between two tags of the same type using javascript or jquery?

For examle if i had:

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

How could i get all the <li>?

I tried using this $units=$(this).nextuntil("h2"); but it didn't work


$('h2:first').nextUntil('h2:last');

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

This of course only works in this particular example. In a more complex markup, you would probably need to be more specific. Like $('h2:eq(2)') or others pseudo-selectors.

0

精彩评论

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

关注公众号