Element: método removeAttribute()

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.

O método Element removeAttribute() remove o atributo com o nome especificado do elemento.

Sintaxe

js
removeAttribute(attrName)

Parâmetros

attrName

Uma string especificando o nome do atributo a ser removido do elemento. Se o atributo especificado não existir, removeAttribute() retorna sem gerar um erro.

Valor de retorno

None (undefined).

Notas de uso

Você deve usar removeAttribute() em vez de definir o valor do atributo como null diretamente ou usando setAttribute(). Muitos atributos não se comportarão conforme o esperado se você defini-los como null.

Exemplos

js
// Dado: <div id="div1" disabled width="200px">
document.getElementById("div1").removeAttribute("disabled");
// Agora: <div id="div1" width="200px">

Especificações

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

Compatibilidade de 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
removeAttribute

Legend

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

Full support
Full support
See implementation notes.

Veja também