JQuery-> Get brother Dollar?

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.