May 14, 2012
How to count whitespaces as a childnodes?
Question by user1394479
Whitespace count as empty text element in a DOM.
How can I count these whitespaces?
for example
<body>
<div>
</div>
<div>
</div>
</body>
how many whitespaces(childNodes) inside the body element?
how many whitespaces(childNodes) inside each div element?
Answer by Starx
If you are trying to see how many elements are empty? Then I am giving you a jQuery solution instead.
bodyChild = $("body :empty").length;
divHcild = $("#divid :empty").length;
Using them, you can know what many elements are completely empty inside an element.
Update:
To get all the child element, you can use something like this
Body:
var children = document.getElementByTagName('body').childNodes;