'Behaviour of :defined pseudo selector class

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source