Hello Readers,
Jquery each() method is used to run for each matched element.It is used to loop through each element of the target jQuery object.
Synyax: $(selector).each(function(index,element))
Example:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("li").each(function(){
alert($(this).text())
});
});
});
</script>
</head>
<body>
<button>Alert the value of each list item</button>
<ul>
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
<li>Fifth</li>
</ul>
</body>
</html>
In above example you can find each list one by one in alert box. jquery each() method run for each matched element.
Thanks
0 Comment(s)