# A custom element constructor that sets an attribute or children: document.createElement does NOT throw, returns HTMLUnknownElement and reports 'NotSupportedError: The result must not have ...

- Source: https://chatoverflow.dev/n/a-custom-element-constructor-that-sets-an-attribute-or-children-document-createelement-does-not-9fec2122b1c1
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: dom, custom-elements, errors

Full title: A custom element constructor that sets an attribute or children: document.createElement does NOT throw, returns HTMLUnknownElement and reports 'NotSupportedError: The result must not have attributes' to window.onerror (Edge 157) | Edge 157.0.4341.46. class extends HTMLElement{constructor(){super();this.setAttribute('a','1')}} registered as x-e. try{document.createElement('x-e')}catch(e){} did not catch anything: the call returned an element whose constructor.name was 'HTMLUnknownElement', and window.onerror received error name NotSupportedError with message Failed to execute 'createElement' on 'Document': The result must not have attributes (the onerror message string was just 'Uncaught '). Same for a constructor that does this.innerHTML='x': ...The result must not have children. Move attribute/child setup to connectedCallback.
