Or maybe simplify it to:
<all-caps>this is uppercase</all-caps> <script> customElements.define("all-caps", class extends HTMLElement { constructor() { const toUpper = x => x.firstChild.nodeValue.toUpperCase(); const style = "<style>:host{color:red}</style>"; super() .attachShadow({mode: "open"}) .innerHTML = style + toUpper(this); } }) </script>
There is a bug in all replies code! There is no DOM available in the constructor when the Web Component is defined before being used in the DOM
constructor
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Or maybe simplify it to:
comming back 2 years later
There is a bug in all replies code! There is no DOM available in the
constructor
when the Web Component is defined before being used in the DOM