How to use each() in jQuery?

The jQuery each function is used to iterates through DOM elements similar to a foreach loop in other languages. This function iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. The call back function is triggered in the context of the current DOM element, so you can use this keyword to refer the currently matched element.


  1. index - The index position of the element
  2. element - The current element
run this source code Try it Yourself
  • Red
  • Blue
  • Green

Full Source

Loop Through Arrays

jQuery $.each() works for objects and arrays both.

run this source code Try it Yourself

Full Source

 (C) 2023    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About