Element.removeAttribute()

removeAttribute elimina un atributo del elemento especificado.

Sintaxis

js
element.removeAttribute(attrName);
  • attrName es una cadena que nombra el atributo a ser eliminado de element.

Ejemplo

js
// <div id="div1" align="left" width="200px">
document.getElementById("div1").removeAttribute("align");
// ahora: <div id="div1" width="200px">

Notas

Debe usarse preferiblemente removeAttribute en lugar de establecer el valor del atributo a null usando setAttribute.

Intentar eliminar un atributo que no existe en el elemento no disparará una excepción.

Métodos DOM que tratan con atributos de elementos:

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
hasAttribute (DOM 2) hasAttributeNS (en-US) - -
removeAttribute (DOM 1) removeAttributeNS (en-US) removeAttributeNode (en-US) -

Especificaciones

Specification
DOM Standard
# ref-for-dom-element-removeattribute①

Compatibilidad con navegadores

BCD tables only load in the browser