Element removeAttribute() Method - Javascript DOM

Javascript examples for DOM:Element removeAttribute

Description

The removeAttribute() method removes attribute by name.

Parameter Values

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

Return Value:

No return value

The following code shows how to Remove the href attribute from element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<a id="myAnchor" href="http://www.java2s.com">A Link: go to java2s.com</a>

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

<script>
function myFunction() {//from w w  w  . ja  va2 s  . com
    var elmnt = document.getElementById("myAnchor");
    elmnt.removeAttribute("href");
    
}
</script>

</body>
</html>

Related Tutorials