When you get the sibling element of the specified element, you can use theadjacent Sibling combinator (+), where + Both sides of the content are selector expressionIf you want to get all of theH1 's direct sibling element H2
<div>
can be used directly$ (' H1 + H2 ') //Select All H2 elements that is adjacent siblings of H1 elements.
If you want to filter H1 's sibling elements, you can also use$ (' H1 '). Siblings (' h2,h3,p '); Select all H2, H3, and P elements that is siblings of H1 elements.
If you want to get all the sibling elements after the current element, you can use thenextAll()For example, for the following HTML code<ul> <li>first item</li> <li class= "selected" >second item</li> <li >third item</li> <li>fourth item</li> <li>fifth item</li></ul>
If you want to get all the LI elements after the second entry, you can use the following code$ (' li.selected '). Nextall (' Li ');
The example above can also be usedGeneral Sibling Combinator (~)To achieve$ (' li.selected ~ li ');
Get direct sibling elements can also be used without selector, directly usingnext().var topheaders = $ (' h1 '); Topheaders.next (' H2 '). CSS (' margin ', ' 0);