|
Each
A generic iterator function, to iterate over the elements in the result set. each(callback)Iterates over the elements in a set, such as the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed. callback A function. The callback function is passed the iteration index and the current element.
In the scope of the callback function, ExamplesThe following two scripts demonstrate a simple iteration over the elements in
the This script sets the background color of each of the elements to red. (This is just to demonstrate how this function works. It is easier to change the style of a set of HTML elements using the css() function; see css().)
The following script adds a random integer to each element in the result set.
This script gets the row index (of the current element in the set) and puts it in a paragraph.
Using
|
Selector | Matched element | Matched element after script execution |
---|---|---|
p |
<p data-translate="first"></p> |
<p>primero</p> <p>último</p> <p>dirección de correo electrónico</p> |
|