Home >>jQuery Tutorial >jQuery each() Method
jQuery each() method in jQuery is used to specifies a function to run for each matched element.
Syntax:$(selector).each(function(index,element))
Parameter | Description |
---|---|
function(index,element) | It is a required parameter which is used to run a function for each matched element.
|
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$("li").each(function(){
alert($(this).text())
});
});
});
</script>
</head>
<body>
<button class="btn1">Click me to alert the value of each list item</button>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</body>
</html>