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.
![]() |
![]() |
![]() |
![]() |
![]() |
|
---|---|---|---|---|---|
removeAttribute |
Yes | Yes | Yes | Yes | Yes |
element.removeAttribute(attributename)
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute to remove |
No return value.
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: