Método HTML DOM removeAttributeNode()
❮ El Objeto ElementoEjemplo
Elimina el nodo de atributo de clase de un elemento <h1>:
var elmnt = document.getElementsByTagName("H1")[0]; // Get the first <h1> element in the document
var attr = elmnt.getAttributeNode("class"); // Get the class attribute node from <h1>
elmnt.removeAttributeNode(attr); // Remove the class attribute node from <h1>
Definición y uso
El método removeAttributeNode() elimina el atributo especificado de un elemento y devuelve el atributo eliminado, como un objeto Attr Node .
La diferencia entre este método y el método removeAttribute() es que el método removeAttribute() elimina el atributo con el nombre especificado , mientras que este método elimina el objeto Attr especificado . El resultado será el mismo. Además, el método removeAttribute() no tiene valor de retorno , mientras que este método devuelve el atributo eliminado, como un objeto Attr.
Sugerencia: use el método getAttributeNode() para devolver un nodo de atributo de un elemento.
Sugerencia: use el método setAttributeNode() para agregar un nodo de atributo a un elemento.
Compatibilidad con navegador
Method | |||||
---|---|---|---|---|---|
removeAttributeNode() | Yes | Yes | Yes | Yes | Yes |
Sintaxis
element.removeAttributeNode(attributenode)
Valores paramétricos
Parameter | Type | Description |
---|---|---|
attributenode | Attr object | Required. The attribute node you want to remove |
Detalles técnicos
Valor devuelto: | Un objeto Attr, que representa el nodo de atributo eliminado |
---|---|
Versión DOM | Objeto de elemento de nivel básico 1 |
Más ejemplos
Ejemplo
Elimina el nodo de atributo href de un elemento <a>:
var elmnt = document.getElementById("myAnchor"); // Get the <a> element with id="myAnchor"
var attr = elmnt.getAttributeNode("href"); // Get the href attribute node from <a>
elmnt.removeAttributeNode(attr); // Remove the href attribute node from <a>
páginas relacionadas
Tutorial HTML: Atributos HTML
Referencia HTML DOM: el objeto de atributo HTML DOM
Referencia HTML DOM: método removeAttribute()
Referencia HTML DOM: Método getAttributeNode()
Referencia HTML DOM: método setAttributeNode()
❮ El Objeto Elemento