jquery Traversal node

Source: Internet
Author: User
Tags prev

1.chirldren ()

Html:

<body>

<p></p>

<ul>

<li></li>

</ul>

</body>

jquery Code:

var bodylength=$ (' body '). Chirldren (). length; Gets <body> the number of child elements below, with a result of 2

var plength=$ (' P '). Chirldren (). length;//gets the number of child elements under the <p> tag, the result is 0

var ullength=$ (' ul '). Chirldren (). length;//gets the number of child elements under the <ul> tag, the result is 1

Attention! The Chirldren () method considers only child elements regardless of any descendant elements.

2.next ()

Html:

<body>

<p></p>

<ul>

<li></li>

</ul>

</body>

jquery Code:

var $p 1=$ (' P '). Next ();//Get the sibling elements immediately following the <p> element

Results:

<ul>

<li></li>

</ul>

3.prev ()

Html:

<body>

<p></p>

<ul>

<li></li>

</ul>

</body>

jquery Code:

var $ul =$ (' ul '). Prev (); Get the sibling elements immediately before the <ul> element

Results:

<p></p>

4.siblings ()

Html:

<body>

<p></p>

<span></span>

<ul>

<li></li>

</ul>

</body>

jquery Code:

var $span =$ (' span '). siblings ();//Get <span> tagged sibling elements

Results:

<p></p>

<ul>

<li></li>

</ul>

5.closest ()

Used to get the closest matching element. First, check if the current element matches, if the match returns the ability directly, the mismatch will look up the parent element, step up until the element matching the selector is found, and return an empty jquery object if nothing is found.

6. Other: Find (), filter (), Nextall (), Prevall (), parent (), parents ()

jquery Traversal node

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.