Javascript DOM HTML Element removeAttribute() Method

Introduction

Remove the class attribute from an <h1> element:

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

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.democlass {//from   www.j av a  2  s  .com
  color: red;
}
</style>
</head>
<body>

<h1 class="democlass">Hello World</h1>

<p id="demo">Click the button to remove the class attribute from the h1 element.</p>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  document.getElementsByTagName("H1")[0].removeAttribute("class");
}
</script>

</body>
</html>

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

The element.removeAttributeNode() method removes the specified Attr object from an element.

This element.removeAttribute() method has no return value, while the removeAttributeNode() method returns the removed attribute, as an Attr object.

element.removeAttribute(attributename);

Parameter Values

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



PreviousNext

Related