.each()
method
Iterates over a jQuery set, executing a function for each matched element.
Syntax
$(selector).each(function(index, element))
Example
javascript
// Iterate list items
$('li').each(function(index, el) {
console.log(index, $(el).text());
});
// Collect values
const values = [];
$('input[type=checkbox]:checked').each(function() {
values.push($(this).val());
});
// Modify each element
$('.price').each(function() {
const p = parseFloat($(this).text());
$(this).text('$' + (p * 1.1).toFixed(2));
});