- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery Misc each() Method
The each() method in jQuery is used to execute a function for each matched element.
Syntax
The syntax is as follows −
$(selector).each(function(index,ele))
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 −
Example
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("li").each(function(){ alert($(this).text()) }); }); }); </script> </head> <body> <h2>Devices</h2> <ol> <li>TV</li> <li>Laptop</li> <li>Headphone</li> <li>Earphone</li> <li>SSD</li> </ol> <button>Get each element</button> </body> </html>
Output
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.
- Related Articles
- jQuery Misc toArray() Method
- jQuery Misc get() Method
- jQuery Misc param() Method
- jQuery eq() method
- jQuery toggle() Method
- jQuery is() Method
- jQuery $.proxy() Method
- jQuery after() method
- jQuery before() Method
- jQuery children() method
- jQuery next() method
- jQuery nextAll() method
- jQuery attr() Method
- jQuery fadeIn() Method
- jQuery fadeTo() Method

Advertisements