Usage: 1. Used to specify the function to be run for each matching element. The syntax is "$(selector).each(function(index,element))"; 2. Used to traverse the specified object and Array, the syntax is "$.each (object or array to be traversed, function used for loop execution)".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
1. The each() method specifies the function to be run for each matching element.
Tip: Returning false can be used to stop the loop early.
$(selector).each(function(index,element))
function(index,element)required. Specifies the function to run for each matching element.
The example is as follows:
Output result:
After clicking the button:
2. The jQuery.each() function is used to traverse the specified objects and arrays.
Syntax
$.each( object, callback )
object Object type specifies the object or array that needs to be traversed.
callback Function type specifies the function used for loop execution.
Examples are as follows:
Output results:
##Related video tutorial recommendations:The above is the detailed content of What is the usage of each in jquery. For more information, please follow other related articles on the PHP Chinese website!