function getChildElementsByTagName ( element, tagName ) {
var children = [];
tagName = tagName && tagName.toLowerCase();
for ( var child = element.firstChild; child; child = child.nextSibling ) {
if ( child.nodeType === 1 && (!tagName || child.nodeName.toLowerCase() === tagName) ) {
children.push( child );
}
}
return children;
}
alert(getChildElementsByTagName( document, 'html' ).length)
alert(getChildElementsByTagName( document.body, 'div' ).length)