EDIT: This is the dumbest question I've asked on SO. I'll keep it, to remind myself not to ask questions too quickly.
How can I check if the DOM node I have selected is the html node? I have noticed that it does not have the usual properties. For example:
var div = document.getElementsByTagName('div')[0];
var html = document.getElementsByTagName('html');
div instanceof HTMLElement; // true
html instanceof HTMLElement; // false
div.tagName; // "DIV"
html.tagName; // undefined
In particular, I would like a check that works for all DOM nodes (div, span, etc.). The issue is that my code crawls up the DOM and checks for a certain property; if the code does not find the property, it reaches the html node and throws an error because of this line:
if (node.tagName.toUpperCase() !== 'OBJECT') { }
This throws a TypeError when node is the html node, because node.TagName is undefined.
Thanks in advance.