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 añade un nuevo atributo o cambia el valor de un atributo con el namespace dado y el nombre.

Sintaxis

js
elemento.setAttributeNS(namespace, nombre, valor);
  • namespace es un string especificando el namespace del atributo.
  • name es un string identificando el atributo a ser puesto.
  • value es el string del valor deseado del nuevo atributo.

Ejemplo

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

Especificaciones

Specification
DOM
# ref-for-dom-element-setattributens①

Compatibilidad con navegadores

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
setAttributeNS

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support