-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating non-ugraded defined custom element : createElement(tagname, {upgrade:false})
#1097
Comments
I suspect this will be the result with cc @rniwa |
Hmm, why would it be impossible to upgrade in the latter case? |
Maybe this is an implementation issue, but on Firefox and Chromium, class A extends HTMLElement {}
customElements.define("a-a", A);
const d = new Document();
const a = d.createElement("a-a");
document.adoptNode(a)
document.body.append(a);
customElements.upgrade(a)
console.log(a instanceof A); // gives false |
That's because you're creating an element in the null namespace rather than the HTML namespace. Use |
Oh, thanks, I didn't know. It seems we can even do: const doc = document.implementation.createDocument(
"http://www.w3.org/1999/xhtml",
"html",
null,
);
// document.implementation.createHTMLDocument() also possible, but will create .body properties, etc.
doc.createElement("a-a"); |
I just noticed that in the two solutions (template and HTML namespace) :
I think the (1) behavior is an issue as we might have some code using So we need to do something like: const doc = document.implementation.createDocument(
"http://www.w3.org/1999/xhtml",
"html",
null,
);
function createElement(tagname) {
const elem = doc.createElement(tagname);
document.adoptNode(elem);
return elem;
} |
I don't think That |
Indeed, I may have misread the MDN documentation. It seems the best way would then to use |
I would recommend always checking with the specification. (Filing an issue against MDN if you find that page where it claims that would be useful.) If you search for |
It could be great if we could easily create non-ugraded defined custom element.
Currently, to do that, we need to create a
<template>
element, set its content with.innerHTML
, and then fetch the element :We can also create the element on another document, but then the element is impossible to upgrade :
The text was updated successfully, but these errors were encountered: