Element.setAttributeNS()
setAttributeNS
adiciona um novo atributo ou modifica o valor de um atributo com um namespace e um nome.
Syntax
element.setAttributeNS(namespace,name,value)
namespace
é uma string especificando o namespace do atributo.name
é uma string identificando o atributo que sera definido.value
é o novo valor desejado para o atributo.
Exemplo
var d = document.getElementById("d1"); d.setAttributeNS("http://www.mozilla.org/ns/specialspace", "align", "center");
Notas
DOM methods dealing with element's attributes:
Not namespace-aware, most commonly used methods | Namespace-aware variants (DOM Level 2) | DOM Level 1 methods for dealing with Attr nodes directly (seldom used) |
DOM Level 2 namespace-aware methods for dealing with Attr nodes directly (seldom used) |
---|---|---|---|
setAttribute (DOM 1) |
setAttributeNS |
setAttributeNode (en-US) |
setAttributeNodeNS (en-US) |
getAttribute (DOM 1) |
getAttributeNS (en-US) |
getAttributeNode (en-US) |
getAttributeNodeNS (en-US) |
hasAttribute (en-US) (DOM 2) |
hasAttributeNS (en-US) |
- | - |
removeAttribute (DOM 1) |
removeAttributeNS (en-US) |
removeAttributeNode (en-US) |
- |