View Single Post
Old 09-13-2012, 05:07 PM   PM User | #1
docco
New Coder

 
Join Date: Aug 2012
Posts: 67
Thanks: 18
Thanked 0 Times in 0 Posts
docco is an unknown quantity at this point
A note of Child in MSIE and Crome

With the same method to calculate the number of Child in DOM, I have the different results in MSIE and in Crome. MSIE throws the right result while Crome throws the wrong. Please check the code below to see:

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>calculate Child Number</title>
</head>
<body>
<script type="text/javascript"> 
itemarray = new Array(); 
itemarray[100] = 'This is Item 100'; 

function addtocart(ref) { 
var parentel = document.getElementById('itemlist'); 
newrow = document.createElement('div'); 
newrow.innerHTML = itemarray[ref.id]; 
parentel.appendChild(newrow); 
} 
function getParentLength() {
var parente = document.getElementById('itemlist');
var nodes=parente.childNodes;
alert(nodes.length);
}
</script> 
<p><button id="100" onclick="addtocart(this);return false;">add Hat 100</button></p>
<p><button onclick="getParentLength()">Check number of Child</button></p>
<h2>Your cart:</h2> 
<div id="itemlist"> 
</div> 
</body>
</html>
Anyone have any idea?
docco is online now   Reply With Quote