Document.createAttribute()
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.
El método Document.createAttribute()
crea un nuevo nodo de tipo atributo (attr), y lo retorna. El objeto crea un nodo implementando la interfaz Attr
. El DOM no impone que tipo de atributos pueden ser agregados a un particular elemento de esta forma.
Nota: El texto pasado como parametro es convertido a minusculas.
Sintaxis
js
atributo = document.createAttribute(nombre);
Parametros
nombre
es un string conteniendo el nombre del atributo.
Valor que retorna
Un nodo Attr
nodo.
Excepciones
INVALID_CHARACTER_ERR
si el parametro contiene caracteres invalidos para un atributo XML .
Ejemplo
js
var nodo = document.getElementById("div1");
var a = document.createAttribute("miAtributo");
a.value = "nuevoVal";
nodo.setAttributeNode(a);
console.log(nodo.getAttribute("miAtributo")); // "nuevoVal"
Especificaciones
Specification |
---|
DOM # dom-document-createattribute |
Compatibilidad del Navegador
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createAttribute |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
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.