Home > Article > Web Front-end > Usage examples of andSelf() method in jQuery_jquery
The example in this article describes the usage of the andSelf() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method can add the previously selected element to the current element collection.
Grammar structure:
After the above code is run, the text color in the third and fourth li is set to green. Look at the following code again:
After the above code is run, the text color in the second, third and fourth li is set to green.
The difference in the running results of the two codes is due to the andSelf() method.
Analyze the execution process of the code: first, use the class selector to select the second li element, and then use the nextAll() method to convert the third and fourth elements to the current selection. If you start calling the css() method here, it will be the result of the first piece of code. If you call the andSelf() method, the previously selected element will be added to the current element collection, and then the css() method is called, and the font color in the three li elements will turn green.
Example code:
I hope this article will be helpful to everyone’s jQuery programming.