element.setAttributeNS

概要

setAttributeNS は指定の名前空間と名前で新しい属性を追加したり、属性の値を変更します。

構文

element.setAttributeNS(namespace,name,value)
  • namespace は属性の名前空間を指定する文字列です。
  • name はセットしたい属性を特定する文字列です。
  • value は新しい属性の希望する文字列値です。

var d = document.getElementById("d1");
d.setAttributeNS("http://www.mozilla.org/ns/specialspace", "align", "center");

Notes

DOM メソッドは要素の属性を取り扱います。

名前空間に無関係、
最も一般的に使用されるメソッド
名前空間に限定される変数
(DOM Level 2)
Attr ノードを直接扱う DOM レベル 1 のメソッド
(ほとんど使用されない)
Attr ノードを直接扱う DOM レベル 2 名前空間に限定されるメソッド
(ほとんど使用されない)
setAttribute (DOM 1) setAttributeNS setAttributeNode setAttributeNodeNS
getAttribute (DOM 1) getAttributeNS getAttributeNode getAttributeNodeNS
hasAttribute (DOM 2) hasAttributeNS - -
removeAttribute (DOM 1) removeAttributeNS removeAttributeNode -

仕様