December 2013
Intermediate to advanced
384 pages
9h 54m
English
$("p").each(function (idx){ $(this).html("This is paragraph " + idx); });
The .each(function) method is one of the most important jQuery object methods because it allows you to traverse all elements in the jQuery set and perform actions on each of them individually. This is different from just applying the same action to all items in the query.
The .each() method allows you to specify a function to run for each element in the jQuery object set. The function is passed an index number as the first argument. Inside the function, the this variable points to the current DOM element.
To illustrate using .each(), check out the following snippet of code. It ...
Read now
Unlock full access