To select elements based on their position in the document tree, use the Hierarchy Selectors.
The Hierarchy Selectors work by examining the position of target elements relative to other elements:
$("parent > child"): selects "child" elements that are immediate descendants of the "parent"$("ancestor descendant"): selects "descendant" elements as long as they have an "ancestor" element somewhere above them$("prev + next"): selects the "next" element if it is immediately preceded by a "prev" element$("prev ~ siblings"): selects all "siblings" elements that come after a "prev" element
This is paragraph 1
This is paragraph 2
This is paragraph 3
This is paragraph 4
This is paragraph 5