> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/browser/dom/type/element/+ext/elem.isheading.md).

# elem.isHeading

{% tabs %}
{% tab title="💾 程式" %}

* [replit](https://replit.com/@pegasusroe/elemisInsideselector#script.js)

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

💈範例：

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

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

{% endtab %}

{% tab title="👥 相關" %}

* [Element](/web/browser/dom/type/element.md)
  {% endtab %}
  {% endtabs %}
