jQuery Misc each() Method

The each() method in jQuery is used to execute a function for each matched element.


The syntax is as follows −


Above, the index is the position of the selector, whereas ele is the current element.

Let us now see an example to implement the jQuery each() method −


 Live Demo

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<button>Get each element</button>


This will produce the following output −

Click “Get each element” to fetch each element one by one in the alert box −

On clicking “OK”, the next li would be visible −

In the same way, all other li elements would be visible.