The difference between the parents () function and the parent () function of jquery

Source: Internet
Author: User
Tags api manual

The difference between the parents () function of jquery and the parent () function:
In fact, in jquery, the concept of function or selector is very easy to understand, as long as the API manual is skilled enough to easily distinguish, the title of the function in fact, but we still do some simple introduction, after all, it may be more convenient.
A. Parents () function:
This function can get all the parent elements of a matching element, code example:

$ (". Mayi"). Parents (). CSS ("Color", "red");

The code above can set the font color of all parent elements of all elements with the class attribute value of "Mayi" to red.
Look at a complete code example:

<! DOCTYPE html> 

The above code can set the font color in all parent elements of a span element to red.
Two. Parent () function:
This function can be able to get all the first-level parent elements of all matching elements, not all parent elements.

$ (". Mayi"). Parents (). CSS ("Color", "red");

The code above can set the font color to red in the first-level parent element of an element with a class attribute value of Mayi.
Look at a complete code:

<! DOCTYPE html> 

The above code can only be set to red in the font color of "Ant tribe one by one" in the first-level parent element of the SPAN element.
The biggest difference between the two functions is the return of the parent element, from the name of the function can also be perceived, with S can get all the parent element, no s can only get a primary parent element, very simple here is not more introduction, you can see the relevant reading.
Related reading:
The 1.css () function can be found in the section of the CSS () method of jquery .
The 2.parent () function can be found in the section of the parent () method of jquery .
The 3.parents () function can be found in the parents () method section of jquery .

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.