Unknown Elements vs Undefined Custom Elements

注意:

  • 沒有 "-" 的標籤 (如:<nosuchtag>) 會被視為 HTMLUnknownElement

  • 但有 "-" 的標籤 (如:<undefined-element>) 會被視為 HTMLElement❗️

const {log} = console;

[
    // <tabs> is an "unknown" element
    tag('tabs') instanceof HTMLUnknownElement,      // true

    // <x-tabs> is an "undefined" custom element
    tag('x-tabs') instanceof HTMLElement,           // true

].forEach(x => log(x));

// helper function
function tag(name){
    return document.createElement(name);
}

Last updated