Jun 27, 2007

clean up the white-space text

            document.documentElement.firstChild.nextSibling.firstChild;
            
Sometime the above works in IE, but not work in FireFox, because IE ignore the whitespace text, but fireFox does not to solve this problem you need to call this function, before access it.

            function cleanWhitespace( element ) {
            element = element || document;
            var cur = element.firstChild;
            while ( cur != null )
            {
            if ( cur.nodeType == 3 && ! /\S/.test(cur.nodeValue) )
            {
            temp = cur;
            cur = cur.nextSibling;
            temp.parentNode.removeChild(temp);
            }
            else
            {
            if ( cur.nodeType == 1 )
            {
            cleanWhitespace( cur );
            }
            cur = cur.nextSibling;
            }
            }
            }