The example in this article describes the usage of each() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method can execute a function with each element in the matching element set as the context.
Whenever the function is executed, the execution environment of the function is a different DOM element in the matching element collection, and the index of this element in the collection will be passed to this function, and the index value starts from 0. Returning false can be used to stop the loop early. Returning true will continue to execute the function until every element in the matching element is traversed.
The each() method is different from the jQuery.each() method. The each() method can only traverse JQuery objects, while the jQuery.each() method can traverse any object.
Grammar structure:
Parameter list:
Example code:
The above code can facilitate each element in the li element collection, and then return the text in the li element.
I hope this article will be helpful to everyone’s jQuery programming.