Count how many elements in a div

If you want the number of descendants, you can use

var element = document.getElementById("theElementId");
var numberOfChildren = element.getElementsByTagName('*').length

But if you want the number of immediate children, use

element.childElementCount

See browser support here: http://help.dottoro.com/ljsfamht.php

or

element.children.length

See browser support here: https://developer.mozilla.org/en-US/docs/DOM/Element.children#Browser_compatibility

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)