What's the difference between HTMLElement
and Element
?
document.createElement("div") instanceof Element
gives true
document.createElement("div") instanceof HTMLElement
gives true
HTMLElement === Element
gives false
If you just need to check for the specific type of element, you can use the .is() method, which returns a Boolean value: JS. HTML.
However, in common usage the terms HTML element and HTML tag are interchangeable i.e. a tag is an element is a tag. For simplicity's sake of this website, the terms "tag" and "element" are used to mean the same thing — as it will define something on your web page.
Angular elements are Angular components packaged as custom elements (also called Web Components), a web standard for defining new HTML elements in a framework-agnostic way.
An HTMLElement
is an Element
, as defined in the HTML extension to the DOM Level 2 Core specification:
interface HTMLElement : Element { attribute DOMString id; attribute DOMString title; attribute DOMString lang; attribute DOMString dir; attribute DOMString className; };
Element
(per specification) refers to the Element
interface as it is defined in the DOM Core Level 2 specification (there is also another DOM Core specification (working draft) though).
Update: There are a lot of specifications out there and it is not totally clear which browsers use which one (to me).
Maybe someone else has more insight...
But in any case, Element
is a more generic interface than HTMLElement
and the latter inherits from the former.
Update 2: A nice way to see the inheritance structure is to execute console.dir(elementReference)
for any element (works in Chrome/Safari, needs Firebug for Firefox).
HTMLElement refers explicitly to an HTML element whereas Element may refer to an XML element. However, HTMLElement is technically a subset of Element.
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