jQuery > Traversing methods

.each() - Iterate through each element in jQuery

How to iterate through each specified element of the page in jQuery?


To iterate through each specified element of the page, each() method can be used.

 <script>
      $('p').each(function (index) { alert(index + ': ' + $(this).text()); });
  </script>

Above code snippet will iterate through every paragraph of the page and alert its zero based index (position/order in the page from top and its text).

 Views: 6563 | Post Order: 41



Write for us






Hosting Recommendations