💾elem.isHeading

// check if an element is a heading (h1 ~ h6)
Object.defineProperty(Element.prototype, 'isHeading', {
    get(){ return this.matches("h1,h2,h3,h4,h5,h6"); }
});

💈範例:

function $(selector) {
    return document.querySelector(selector)
}

$('h1').isHeading,                 // true
$('#p1').isHeading,                // false

Last updated