The usage and difference between the parent () and parents () Methods of jQuery, jqueryparent

Source: Internet
Author: User

The usage and difference between the parent () and parents () Methods of jQuery, jqueryparent

Usage and difference of the parent () and parents () methods:
The functions of these two methods are similar. Both methods can obtain parent-level elements, but they are not exactly the same. Let's take a look at the differences between them using examples.
Start with the concept:
1. The parent () method can obtain a set of first-level parent elements matching elements, that is, it obtains not all ancestor elements matching elements, but only parent elements.
2. The parents () method can obtain all the ancestor elements (excluding the root element) of the matching element, not just the first parent element.
See the following code example:

<! DOCTYPE html> 

Click the corresponding button to view the different effects of the parent () and parents () functions.

The original address is: Mod = viewthread & tid = 5775.


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: 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.