I had a script as follows
const custElem = document.createElement('my-elem')
let res = custElem.matches(':defined');
console.log(`custElem.matches(':defined'): ${res}`);
res = custElem.matches(':not(:defined)');
console.log(`custElem.matches(':not(:defined)'): ${res}`);
customElements.define('my-elem', class extends HTMLElement {
constructor () {
super()
}
});
res = custElem.matches(':defined');
console.log(`After definition: custElem.matches(':defined'): ${res}`); // EXPECTED TRUE
I expected the last log to yield true
. Why does custElem
fail to match the :defined
selector even after the definition of the custom element?