jquery selector: Gets the parent element, sibling element, child element

Source: Internet
Author: User

The advent of jquery has provided a lot of convenience to the vast number of developers. From the need to own a knock code, to the direct call method, undoubtedly greatly improve the efficiency of website development. Some of the methods in jquery are very practical. The following is a description of the jquery selector: Gets the parent element, sibling element, child element method.

First, get the parent element

1.parent ()

Gets the parent element of the specified element, note: is the parent element closest to the specified element.

2.parents ()

Gets all the parent elements of the specified element, note: All parent elements, including body,html

Second, get the sibling element

1.next ()

Gets the next sibling element of the specified element (note: Is the next sibling element)

2.nextAll ()

Gets all sibling elements following the specified element (note: all sibling elements)

3.andSelf ()

Gets the specified element, which is itself. This method can be used in the use of it? In fact, it is also very common.
For example: Gets all the sibling elements behind the specified element, followed by the specified element

This time you can write $ ('. Div1 '). Nextall (). Andself ()

4.prev ()

Gets the previous sibling element of the specified element. (Contrary to next () method)

5.prevAll ()
Gets all the sibling elements in front of the specified element. (Contrary to the Nextall () method)

Third, get child elements

1.chidren ()

Gets all child elements under the specified element, note: Chidren () traverses only a single level.

2.find ()

. Find () is similar to the. Children () method, but find () must have parameters, that is, it must pass a parameter (selector) to find (). The Find () method is to get all child elements under the specified element (regardless of how many layers are nested in the specified element)

This article originates from: http://yunkus.com/article/jquery/37.html

jquery selector: Gets the parent element, sibling element, child element

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.