How do you loop over elements with jQuery each()?
<ul><li>One</li><li>Two</li><li>Three</li></ul>
$('li').each(function (i) {
console.log(i + ': ' + $(this).text());
if (i === 1) return false; // break
});
Console output
0: One
1: Two
See jQuery each().
Learn more about the similar topics:
| Tutorials |
|---|
| jQuery each() and map() |
| jQuery Utility Methods |
| jQuery Plugins |
| Exercises & Assignments |
|---|
| Write a simple jQuery plugin to highlight elements |
| Interview Questions & Answers |
|---|
| How do you loop over elements with jQuery each()? |
| How do you create a jQuery plugin? |