我正在使用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