# elem.attr()

[🔰 JS](https://lochiwei.gitbook.io/web/js) ⟩ [DOM](https://lochiwei.gitbook.io/web/browser/dom) ⟩ [Types](https://lochiwei.gitbook.io/web/browser/dom/type) ⟩ [Element](https://lochiwei.gitbook.io/web/browser/dom/type/element) ⟩ .attr()

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

```javascript
// ⭐️ get/set attribute
Element.prototype.attr = function(name, value){
    if (value !== undefined) { this.setAttribute(name, value) };
    return this.getAttribute(name) || undefined;
};
```

{% endtab %}

{% tab title="⬇️ 應用" %}

* HTML element [attribute](https://lochiwei.gitbook.io/web/browser/dom/type/element/attribute "mention")
  {% endtab %}

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

* [$(), $all()](https://lochiwei.gitbook.io/web/browser/dom/querying-elements/dom)
* ["data-xxx" Attributes](https://lochiwei.gitbook.io/web/browser/dom/type/element/attribute/dataset)
  {% endtab %}

{% tab title="📘 手冊" %}

* MDN ⟩ Element ⟩ .[setAttribute](https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute)()
  {% endtab %}
  {% endtabs %}
