Home >Web Front-end >JS Tutorial >Example of usage of prev() method in jQuery_jquery
The example in this article describes the usage of the prev() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method takes the immediately preceding sibling element of each element in the matching element set.
The collection of sibling elements can be filtered by selectors.
Grammar structure:
Parameter list:
Example code:
Example 1:
I am the p element
I am the p element
The above code can set the font color of the previous element of each p element in the set of p elements under the father element with the class attribute value to blue.
Example 2:
The above code can set the font color of the element whose class attribute value is js in front of each li element in the set of all li elements to red.
I hope this article will be helpful to everyone’s jQuery programming.