HTML DOM Element removeAttribute() Method

Example

Remove the class attribute from an <h1> element:

document.getElementsByTagName("H1")[0].removeAttribute("class");
Try it Yourself »

Remove the href attribute from an <a> element:

document.getElementById("myAnchor").removeAttribute("href");
Try it Yourself »

Description

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


The Difference Between removeAttribute() and removeAttributeNode()

The removeAttribute() method removes an attribute, and does not have a return value.

The removeAttributeNode() method removes an Attr object, and returns the removed object.

The result will be the same.




Syntax

element.removeAttribute(name)

Parameters

Parameter Description
name Required.
The name of the attribute.

Return Value

NONE

Browser Support

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

It is fully supported in all browsers:

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

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.