HTML DOM Element removeAttribute() Method

Definition and usage

removeAttribute() This method removes an attribute from an element.

Tip:Operations to delete non-existent attributes or attributes that are not set but have default values will be ignored.

The difference between removeAttribute() and removeAttributeNode()

removeAttribute() This method deletes an attribute and does not return any value.

removeAttributeNode() This method deletes an Attr object and returns the removed object.

The result will be the same.

See also:

Reference manual:

getAttribute() method

setAttribute() method

hasAttribute() method

hasAttributes() method

getAttributeNode() method

setAttributeNode() method

removeAttributeNode() method

Tutorial:

HTML Attributes

Example

Example 1

Remove the class attribute from the <h1> element:

document.getElementsByTagName("H1")[0].removeAttribute("class");

Try it yourself

Example 2

Remove the href attribute from the <a> element:

document.getElementById("myAnchor").removeAttribute("href");

Try it yourself

Syntax

element.removeAttribute(name)

Parameters

Parameters Description
name Required. The name of the attribute.

Return value

None.

Throw

If the element is read-only and does not allow deletion of its attributes, this method will throw a DOMException exception with the code NO_MODIFICATION_ALLOWED_ERR.

Browser support

element.removeAttribute() It is a DOM Level 1 (1998) feature.

All browsers fully support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 9-11 Support Support Support Support