Answer the question
In order to leave comments, you need to log in
How to distinguish between DOM object and Object object in JS?
How to confidently and cross-browser distinguish between these objects?
You can use properties: .id==string, .attributes==array, but this is indirect.
instanceof something - most likely, there is no cross-browser class.
Who knows the recommendations from the standardizers? Who uses what methods?
Answer the question
In order to leave comments, you need to log in
var isDomElement = document.getElementById('someId') instanceof HTMLElement;
the most important thing is that it is impossible to create an object of the HTMLElement class and its descendants just like that; you can't write
var el = new HTMLElement();
> document.body+''
"[object HTMLBodyElement]"
> document.querySelector('div')+''
"[object HTMLDivElement]"
> document.querySelector('span')+''
"[object HTMLSpanElement]"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question