我正在使用jQuery。我有以下的HTML片段:如何选择两个h2之间的所有元素
<h1>Main Title</h1>
<h2>One header</h2>
<p>some text</p>
<p>more text</p>
<ul><li>a list</li></ul>
<h2>Another header</h2>
<a href="######">one link</a>
<h3>ddd</h3>
<p>eee</p>
<h2>Header 3<h2>
<p>This is a Paragraph</p>
我需要得到是每一个h2元素之间的内容,为了做这样的事情:
First Section text
some text
more text
Second section text
one link
ddd
eee
Third section text
This is a Paragraph
我读过这个资源: http://www.tutorialspoint.com/jquery/jquery-selectors.htm
但仍然无法确定如何去做我所需要的。
在此先感谢!
什么是jQuery的你试过吗? – kunalbhat
尝试使用['.nextUntil()'](http://api.jquery.com/nextUntil/)。就像'$('h2')。each(function(){console.log($(this).nextUntil('h2')。text());})' – Chad
你有没有想过给每个H2一个类并使用.each()? – Brad