JQuery Each

 

The jQuery.each() method is a static method of the jQuery object. So this is a method that’s out there for you to use, and you need to give it a little more info. But there is a bigger payoff with this method: it can be used to iterate over different kinds of things, not just a jQuery collection. In this example, each() method specifies a function to run for each matched element and it will show each value in alert box .

 
 
 
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("li").each(function(){ alert($(this).text()) }); }); }); </script> </head> <body> <button>Get each value!</button> <ul style="font-size: 30px; color: darkblue"> <li>India</li> <li>Australia</li> <li>South Africa</li> </ul> </body> </html>
Output