childNodes.length difference
Different calculation for childNodes.length on 2012 platform
Contents
document.getElementById("testDiv").childNodes.length; is used to find the Child Node count. While configuring DOM for each browser, there is difference while identifying the child node count.
Source Files
Note
The files needed for the sample application are here.
Example
<div id="testDiv">
<p>ABC</p>
<p>DEF</p>
</div>
If we get the value of document.getElementById("testDiv").childNodes.length;, the result will be:
- Maple
- 2, as only DOM nodes are counted
- Webkit
- 5, as both text nodes and DOM nodes are counted
Solution
- On using the document.getElementById("testDiv").childNodes.length; and the operation progresses caution is required.
- Depending on the resolutions always time can vary.
- Remove spaces/enter between tags and text.