Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

76
Views
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?

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs