Element: setAttributeNS() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
setAttributeNS
は、指定された名前空間と名前で、新しい属性を追加したり、属性の値を変更したりします。
構文
js
setAttributeNS(namespace, name, value)
引数
namespace
は属性の名前空間を指定する文字列です。name
は修飾名で属性を識別する文字列です。すなわち、名前空間接頭辞に続いてコロン、続いてローカル名です。value
は新しい属性の希望する文字列値です。
返値
なし (undefined
)。
例
js
let d = document.getElementById("d1");
d.setAttributeNS(
"http://www.mozilla.org/ns/specialspace",
"spec:align",
"center",
);
メモ
setAttributeNS
は名前空間属性のための唯一のメソッドで、完全修飾名、つまり "namespace:localname"
を期待します。
仕様書
Specification |
---|
DOM # ref-for-dom-element-setattributens① |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
setAttributeNS |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.