jQuery Misc each() Method Read Courses Improve Improve Improve Like Article Like Save Article Save Report issue Report The each() Method in jQuery is used to specify the function to run for each matched element. Syntax: $(selector).each(function(index, element)) Parameters: This method accepts single parameter function(index, element) which is mandatory. It is used to run for each matched element. It contains two parameters. index: It holds the index position of selector element. element: It holds the current element. Example 1: This example use each() method to display each paragraph element. <!DOCTYPE html> <html> <head> <title> jQuery Misc each() Method </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> </head> <body style="text-align:center;"> <h1 style = "color:green;" > GeeksForGeeks </h1> <h2>jQuery each() Method</h2> <button>Click</button> <p>Geeks1</p> <p>Geeks2</p> <p>Geeks3</p> <!-- Script use each() method --> <script> $(document).ready(function() { $("button").click(function() { $("p").each(function() { alert($(this).text()) }); }); }); </script> </body> </html> Output: Before Click on the Button After Click on the Button Example 2: This example use each() method to display paragraph element. <!DOCTYPE html> <html> <head> <title> jQuery Misc each() Method </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> </head> <body style="text-align:center;"> <h1 style = "color:green;" > GeeksForGeeks </h1> <h2>jQuery each() Method</h2> <button>Click</button> <p>Geeks1-Geeks2-Geeks3</p> <div style="color:lightgreen;"></div> <!-- Script use each() method --> <script> $(document).ready(function(){ $("button").click(function(){ $("p").each(function(){ $("div").text($(this).text()) }); }); }); </script> </body> </html> Output: Before Click on Button After Click on Button Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now! Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about! Last Updated : 04 Jul, 2023 Like Article Save Article Previous How to append an element in two seconds using jQuery ? Next HTML | DOM Input DatetimeLocal max Property Share your thoughts in the comments Add Your Comment Please Login to comment...