选择两个相同类型的标签之间的所有元素? [英] Select all elements in between two tags of the same type?
本文介绍了选择两个相同类型的标签之间的所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用javascript或jquery选择两个相同类型的标签之间的所有元素?
How could i select all the elements between two tags of the same type using javascript or jquery?
例如,如果我有:
<h1></h1>
<h2><h2>
<li1></li1>
<li2></li3>
<li3></li4>
<h2></h2>
我怎么能得到所有的<li>
?
我尝试使用此$units=$(this).nextuntil("h2");
,但是没有用
I tried using this $units=$(this).nextuntil("h2");
but it didn't work
推荐答案
$('h2:first').nextUntil('h2:last');
演示: http://www.jsfiddle.net/4yUqL/63/
这当然仅在此特定示例中有效.在更复杂的标记中,您可能需要更具体.类似于$('h2:eq(2)')
或其他伪选择器.
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.
这篇关于选择两个相同类型的标签之间的所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文