Gets the sibling element of the specified element, which can be used when the
adjacent Sibling combinator (+), among
+ Both sides of the content are selector expressionSuppose you want to get all of the following examples
H1 '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.
Assuming that you want to get all the sibling elements after the current element, you can usenextAll()
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>
Assuming that you want to get all the LI elements after the second entry, you can use the following code, for example$ (' 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);