I have a custom HTML element that was registered in an external library with a name containing special Unicode characters. I would like to dynamically create an element of that kind, so I tried to use document.createElement
, but doing so results in a runtime error in Chrome and Firefox because, apparently, the name of the element is not valid. Only Safari allows creating the element in this way.
Here is a simplified example:
// External code
class TestElement extends HTMLElement
{ }
customElements.define("emotion-", TestElement); // OK
console.log("custom element registered");
// My code
document.createElement("emotion-"); // Error in Chrome and Firefox
console.log("custom element created");
Note that the HTML spec itself cites emotion-
as an example of a valid custom element name.
How can I create such a custom element in JavaScript?