1, $ (selector). Each (index, element) {}) method iterates through a jquery object and runs the defined function for each matching element.
Index: The index position of the selector.
Element: the current elements.
2, $.each () is used to iterate over algebraic groups and objects. Arrays and array-like objects iterate through a numeric index with a length attribute, from 0 to Length-1. Other objects iterate through their property names.
$.each (array, function (index, value) {})
The callback function of the array is passed one index at a time and the corresponding array value as the parameter.
The callback function of the object passes one key-value pair at a time.
Returns False if the iteration is to be terminated;
Returns a non-false equivalent to continue jumps out of the current iteration and goes to the next iteration.
$(function() { $("#table2 tr TD"). each (function(index, Element) {$ ( This). MouseOver (function() {alert (index); Alert (Element). HTML ()); $( This). css ({' Background ': ' #f00 ')}); }) }) vararr1 = [' 0 ', ' 33 ', ' 889 ']; $.each (arr1,function(Index, value) {Alert (index+": " +value); return(Index = = 1); }) varObj1 = { "Name": ' Roronoa ', ' Age ': ' 25 '} $.each (Obj1,function(Index, value) {Alert (index+": " +value); })})
Jquery-each () method