PDA

View Full Version : how to find number of <div> using javascript


kriskishi
04-15-2005, 11:06 AM
hi friends

here i am building a site builder where i am using many <div> tags the problem is i want to know how many <div> tags are there in the document please help.

kishore
:(

coothead
04-15-2005, 11:30 AM
Hi there kriskishi,

this little snippet should solve your problem. :)
<script type="text/javascript">
<!--
function howMany() {
var divs=document.getElementsByTagName("div");
alert(divs.length);
}
onload=howMany;
//-->
</script>
...just place the code within the head section of your page.

coothead

kriskishi
04-15-2005, 02:23 PM
thank you