![]() |
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> |
Yes the numbers are different
but they are both correct, browsers other than IE add an empty text node to empty divs Code:
|
If you want to get the same answer in all browsers when counting nodes then you need to get rid of all the blank text nodes first and also combine any adjacent text nodes into single text nodes.
See http://javascriptexample.net/dom36.php for a function that you can run that will do this for you. |
depending on what you are trying to do, you may be better testing for children:
Code:
function getParentLength() { |
felgall,
PM was disabled. The normalizeAll function code located at http://javascriptexample.net/dom36.php has unballanced parentheses in the first conditional. Maybe a type-0? The conditional in question is repeated below for clarity: Code:
if((3 === c.nodeType && !/\S/.test(c.nodeValue))) || 8 === c.nodeType) { |
| All times are GMT +1. The time now is 06:13 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.