Iterate over an SR object, executing a function for each matched element.
// <li>A</li><li>B</li>
$('li').each((index, el) => {
console.log(`${index}: ${el.textContent}`);
});
// Console Output:
0: A
1: B
$('li').each(function(index) {
if (index === 2) return false;
$(this).addClass('processed');
});
<li class="processed">Item 0</li>
<li class="processed">Item 1</li>
<li>Item 2</li>
| Parameter | Type | Description |
|---|---|---|
| callback | function | A function to execute for each matched element. The callback receives (index, element) arguments. Inside the callback, this refers to the raw DOM element. Return false to stop iteration early. |
Returns: The original SR object for chaining.