JQuery method for obtaining all parent and peer elements and child elements (recommended ).

Source: Internet
Author: User

JQuery method for obtaining all parent and peer elements and child elements (recommended ).

1. Get the parent Element

$("#id").parent()

Obtain parent-level elements

$("#id").parents()

Obtain all of its ancestor Elements

$("#id").closest()

Obtain the most recent ancestor elements

--------------------------------------------------------------------------------

2. Get the same level element

$("#id").next(selector)

Obtain the next sibling element adjacent to the matching element. If a selector is provided, the next sibling element matching the selector is retrieved.

$("#id").nextAll(selector)

Obtain all the compatriot elements behind the matching element. selector filtering is optional.

$("#id").prev(selector)

Obtain the first compatriot element adjacent to the Matching Element (opposite to next)

$("#id").prevAll(selector)

Obtain all compatriot elements before the current Matching Element (opposite to nextAll)

--------------------------------------------------------------------------------

3. obtain child elements

$("#id").children(selector)

Returns the child element of the matching element. You can use the selector to filter the optional parameters.

$("#id").find(selector)

Obtains the descendant of the current element.

Summary

The above is a small series of jQuery methods for getting all the parent and peer elements and child elements. I hope to help you. If you have any questions, please leave a message, the editor will reply to you in time!

Related Article

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.