14 May 2023

In jQuery, you can use the $.each() method to loop through a collection of elements or objects. In vanilla JavaScript, you can achieve the same functionality using the forEach() method, which is available on arrays.

Source code viewer
  1. const elements = document.querySelectorAll('.my-class');
  2.  
  3. elements.forEach(function(element) {
  4. // Do something with each element
  5. });
Programming Language: ECMAScript