Javascript Reference - HTML DOM removeAttribute() Method








The removeAttribute() method removes the specified attribute.

removeAttributeNode() method removes the specified Attr object, while removeAttribute() method removes the attribute with the specified name. The result will be the same.

Browser Support

removeAttribute Yes Yes Yes Yes Yes

Syntax

element.removeAttribute(attributename) 

Parameters

Parameter Type Description
attributename String Required. The name of the attribute to remove




Return Value

No return value.

Example

The following code shows how to remove the style attribute from a header element.


<!DOCTYPE html>
<html>
<body>
<h1 style="color:red">Hello World</h1>
<button onclick="myFunction()">test</button>
<!--from   ww w.j a v a2 s . c o m-->
<script>
function myFunction()
{
    document.getElementsByTagName("H1")[0].removeAttribute("style"); 
}
</script>

</body>
</html>

The code above is rendered as follows: