Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no HTMLSectionElement and no HTMLArticleElement in Javascript?

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:

  • HTMLNavElement
  • HTMLHeaderElement
  • HTMLMainElement
  • HTMLAsideElement
  • HTMLFooterElement

Does 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?

like image 263
connexo Avatar asked Apr 24 '26 07:04

connexo


1 Answers

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 HTMLElement interface.

like image 91
connexo Avatar answered Apr 25 '26 21:04

connexo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!