How to use children() and each() method in jquery?
Snippet Code
Rate this page :
[ 0 votes]
This simple jquery code allows you to store the div element. Here, children is an array variable which stores the children element of the container div.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(function(){
var children = [];
$("#container").children().each(function() {
children.push(this);
});
function fade(children) {
if (children.length > 0) {
var currentChild = children.shift();
$(currentChild).slideUp("slow", function() {
fade(children);
});
}
}
$(".demo").click(function() {
fade(children);
});
});
</script>
<div id="container">
<div>This is first div</div>
<div>This is second div</div>
<div>This is third div</div>
</div>
<a href="#" class="demo">Click To View Demo</a>