What is the use of jquery .each() function?
Submitted by: AdministratorBasically, 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>
Submitted by:
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>
Submitted by:
Read Online JQuery Developer Job Interview Questions And Answers
Top JQuery Developer Questions
☺ | Explain jQuery? |
☺ | Why we need jQuery? |
☺ | What methods used to provide effects in JQuery? |
☺ | 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? |
☺ | Explain jQuery connect? |
Top Scripting language Categories
☺ | AngularJS Interview Questions. |
☺ | Ext-JS Interview Questions. |
☺ | Dojo Interview Questions. |
☺ | Expert Developer JavaScript Interview Questions. |
☺ | SWFObject Interview Questions. |