Home > Article > Web Front-end > Usage examples of parents() method in jQuery_jquery
The example in this article describes the usage of the parents() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method obtains a set of elements containing the parent elements of all matching elements.
The obtained set of parent elements can also be filtered using expressions.
Grammar structure:
Example code:
Example 1:
The above code can set the font color of all ancestor elements of the li element to red. Because the color attribute is inherited, the font in the li element is red.
Example 2:
The above code can set the font color of the elements whose class attribute value is "ul" among all group selection elements of the li element to red.
I hope this article will be helpful to everyone’s jQuery programming.