CKTIS / JavaScript
Element.removeAttribute — removing an attribute
Element.removeAttribute removes an element's attribute by name. It returns undefined; a missing attribute does not cause an error.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
element.removeAttribute(qualifiedName)Element.removeAttribute removes the element's first attribute with a matching qualified name. It is a DOM method, not a function of ECMAScript itself.
If the element is in the HTML namespace and its node document is an HTML document, the method converts ASCII uppercase letters (A–Z) in qualifiedName to lowercase before looking up the attribute. For example, removeAttribute('DATA-STATE') can remove the data-state attribute. Otherwise, the method uses the argument without changing its case.
Calling element.removeAttribute(qualifiedName) returns undefined, not the removed value. If there is no matching attribute, nothing changes. Attributes in different namespaces can share the same qualified name. A single call removes only the first match. If another matching attribute remains, hasAttribute(qualifiedName) returns true, and getAttribute(qualifiedName) returns the value of the first remaining match. If no matching attribute remains, these methods return false and null, respectively.
Removing an attribute differs from setting an empty string with setAttribute: an empty attribute still exists. The method does not remove the element itself. To identify an attribute by namespace and local name, use removeAttributeNS(namespace, localName).
Examples
const element = document.createElement('div');
element.setAttribute('data-state', 'ready');
console.log(element.getAttribute('data-state'));
const result = element.removeAttribute('data-state');
console.log(element.hasAttribute('data-state'));
console.log(element.getAttribute('data-state'));
console.log(result);
element.removeAttribute('data-state');
console.log(element.hasAttribute('data-state'));Result
ready false null undefined false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.