You can test whether an element is a div or a span like this:
const div = document.createElement('div');
console.log(div instanceof HTMLDivElement);
const span = document.createElement('span');
console.log(span instanceof HTMLSpanElement);
This way of testing so far has worked for most HTML elements I'm aware of.
Unfortunately, the same approach of checking an element type is not available for section and article elements, which would mean I'd probably have to resort to el.tagName === 'SECTION' respectively el.tagName === 'ARTICLE'.
Edit: Just tested, the following globals all don't exist either:
HTMLNavElementHTMLHeaderElementHTMLMainElementHTMLAsideElementHTMLFooterElementDoes anyone know, and have any reference, as of why there are no HTMLSectionElement and HTMLArticleElement globals?
Is this because all of them are technically div elements with a different tag name to provide better semantics?
Thanks to @pointy for his comment pointing this out, the following section of the current HTML specification explains this:
The basic interface, from which all the HTML elements' interfaces inherit, and which must be used by elements that have no additional requirements, is the
HTMLElementinterface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With