childNodes.length difference

Published 2014-10-27 | (Compatible with SDK 3.5,4.5,5.0,5.1 and 2012,2013,2014 models)

Different calculation for childNodes.length on 2012 platform

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


The files needed for the sample application are here.


<div id="testDiv">

If we get the value of document.getElementById("testDiv").childNodes.length;, the result will be:

2, as only DOM nodes are counted
5, as both text nodes and DOM nodes are counted


  1. On using the document.getElementById("testDiv").childNodes.length; and the operation progresses caution is required.
  2. Depending on the resolutions always time can vary.
  3. Remove spaces/enter between tags and text.