Javascript DOM HTML Element removeAttribute() Method remove href attribute from <a>

Introduction

Remove the href attribute from an <a> element:

document.getElementById("myAnchor").removeAttribute("href");

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

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

<script>
function myFunction() {//from   w  w  w. j  a va 2s  .c o  m
  document.getElementById("myAnchor").removeAttribute("href");
}
</script>

</body>
</html>



PreviousNext

Related