jQuery each Method

Last Updated Jul 21, 2015, 12:00:06 PM





jQuery each() method

jQuery each() method iterate over each jQuery object and execute a function for each matched element. The looping will start from 0


The jquery each() method is designed to make DOM looping concise and less error-prone. Whenever the jquery each method called, it iterates over the DOM elements which are part of the jQuery object. Each time the callback runs, it will pass the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword this refers to always the current element.

syntax
Example

The above jquery each method will iterate over the each div in the HTML and change its color when the element gets clicked

Output

The above example code produces the following result


jquery each() method
Try It Now

jQuery Traversal Referances

jQuery Traversal

jQuery Traversal Basics

jQuery Traversal Filters

jQuery Traversing Methods

Sources and Credits

The content and methods in the tutorial has been referred and updated with jQuery API and The jQuery Foundation

Last Updated Jul 21, 2015, 12:00:06 PM