How to find No. of Elements Present in div?? also i want to print list of Element present in div . I have tried this but it is not working ..
<!DOCTYPE html>
<html>
<head>
<title> Div Length</title>
<script type="text/javascript" src="js/jquery-1.6.2.min.js">
</script>
<script>
$(function ()
{
alert(' Elements are ' +$('#main').length);
}
)
</script>
</head>
<body>
<div id="main">
<img src="images/thumb1.jpg"; height="30" width="30" />
<img src="images/thumb2.jpg"; height="30" width="30"/>
<img src="images/thumb3.jpg"; height="30" width="30"/>
<img src="images/thumb4.jpg"; height="30" width="30"/>
<div id="main1">
</div>
<div id="main2">
</div>
</div>
</body>
</html>
I need to find length because i am dynamical adding element in div from j query so at the end i want to check what are all elements that has been added successfully .
Thanks,
$("div#main").children().length
If you want to process each item which has been dynamically added you don't need to get the lenght at all. Instead you probably just what to loop though each one like this
$('#main img').each(function(index){
// Your code
console.log( $(this).html() );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With