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 .