jQuery Tutorial plus Question:

What is the use of jquery .each() function?

Tweet Share WhatsApp

Answer:

Basically, the jQuery .each() function is used to loop through each element of the target jQuery object. Very useful for multi element DOM manipulation, looping arrays and object properties.

Example:
In this example alert box will open 3 times because dom contain 3 <li> tags
<script>
$(document).ready(function(){
$("button").click(function(){
$("li").each(function(){
alert($(this).text())
});
});
});
</script>

<ul>
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>

Download jQuery PDF Read All 91 jQuery Questions
Previous QuestionNext Question
Do you know what is the use of jQuery.data()?Suppose if you have a server control(asp.net server control, Button) and on the click of button you want to call a jquery function, So tell me how you will call a jquery function without postback?