JQuery self-study notes-6 Traversal

Source: Internet
Author: User

What is traversal? JQuery traversal, indicating "moving", is used to "find" (or select) HTML elements based on their relationship with other elements. Start with an option and move it along the option until it reaches your desired element. Shows a family tree. With jQuery traversal, you can easily move up (ancestor), down (descendant), and horizontally (compatriot) in the family tree from the selected (current) element ). This movement is called DOM traversal. Illustration: The <div> element is the parent element of <ul>, and is the ancestor of all the content. The <ul> element is the parent element of the <li> element, and the <li> element on the left of the <div> child element is the parent element of <span>, the child element of <ul> and the descendant of <div>. The <span> element is a child element of <li> and is a descendant of <ul> and <div>. The two <li> elements are siblings (with the same parent element ). The <li> element on the right is the parent element of <B>, the child element of <ul>, and the descendant of <div>. The <B> element is the child element of <li> on the right, and is the descendant of <ul> and <div>. Tip: The ancestor is father, grandfather, great-grandfather, and so on. Future generations are children, grandchildren, and great grandchildren. Siblings have the same parent. JQuery methods are useful for traversing the DOM tree upwards. They are used to traverse the DOM tree upwards: parent () parents () parentsUntil () jQuery parent () method parent () returns the direct parent element of the selected element. This method only traverses the DOM tree at the upper level. The following example returns the direct parent element of each <span> element: instance $ (document ). ready (function () {$ ("span "). parent () ;}); try jQuery parents () method parents () to return all ancestor elements of the selected element, it goes all the way up to the root element of the document (

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.