css selectors - How to select all content between two tags in jQuery -


I have a document with heading and unordered lists.

How can I use jQuery to select a given title (by the name of my unique class) and all the contents between that title and the next title?

Updates:

Your suggestions are great, but what I am not seeing. In the code below, for example, I want to use only "H1" with the id of "Heading 2" and everything, but not including "H1" with the id of "Heading 3" needed.

The above jQuery examples will use the Hing after the first "H" tag, which is not the "H" tag.

... or, correct me if I am wrong :)

  & lt; H1 id = "heading1" & gt; ... & lt; / H1> & Lt; Ul & gt; ... & lt; / Ul & gt; & Lt; P & gt; ... & lt; / P & gt; & Lt; Ul & gt; ... & lt; / Ul & gt; & Lt; P & gt; ... & lt; / P & gt; & Lt; H1 id = "heading2" & gt; ... & lt; / H1> & Lt; Ul & gt; ... & lt; / Ul & gt; & Lt; P & gt; ... & lt; / P & gt; & Lt; Ul & gt; ... & lt; / Ul & gt; & Lt; P & gt; ... & lt; / P & gt; & Lt; H1 id = "heading 3" & gt; ... & lt; / H1> & Lt; Ul & gt; ... & lt; / Ul & gt; & Lt; P & gt; ... & lt; / P & gt; & Lt; Ul & gt; ... & lt; / Ul & gt; & Lt; P & gt; ... & lt; / P & gt;  

Two methods in particular will be very useful in solving this problem :, and . The first time you will catch all the siblings after your selector, and whatever you match with your selector will also give you one thing, in which you have a jQuery object, in which they all are included:

  $ ("#heading2") .nextUntil ("# heading3"). And self (). Css ("background", "red");  

This results in the following:

Enter the image Details here


Comments