Element: hasAttributeNS() メソッド
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。
hasAttributeNS は、現在の要素が指定された属性を持っているかどうかを示す論理値を返します。
構文
js
hasAttributeNS(namespace,localName)
引数
namespaceは属性の名前空間を特定する文字列です。localNameは属性の名前です。
返値
論理値です。
例
js
// 値をセットする前に属性が存在しているか検証します。
const d = document.getElementById("div1");
if (
d.hasAttributeNS("http://www.mozilla.org/ns/specialspace/", "special-align")
) {
d.setAttribute("align", "center");
}
仕様書
| 仕様書 |
|---|
| DOM> # ref-for-dom-element-hasattributens①> |