JavaScript: removeAttribute
The removeAttribute() method removes a named attribute from an HTML element.
What you will learn
- How to remove an attribute by name
- What happens when the attribute is not present
- How attribute removal differs from assigning an empty value
Minimal example
<button id="save" disabled>Save</button>const button = document.querySelector('#save');
if (button) button.removeAttribute('disabled');The button is no longer disabled because the disabled attribute has been removed. Calling the method for an attribute that is not present does nothing.
Syntax
element.removeAttribute('attribute-name');Pass the attribute name as a string, such as class, id, title, or aria-label. For classes, classList.remove() is often clearer when you want to remove only one class while keeping others.
Common mistakes
- Use the attribute name, not a CSS selector such as
.disabled. - Setting an attribute to an empty string is not always the same as removing it; boolean attributes such as
disabledare controlled by presence. - Check that the target element exists before calling the method.