how to set href value of anchor tag in javascript

Answers 1
  • <a id="myAnchor"> Anchor tag </a>
       document.getElementById("myAnchor").href = "";
       let hrefVal = document.getElementById("myAnchor").href ;
    Using href property on element you can set the href value in javascript. You can use href property for both set and get the value of anchor tag in javascript.
  • Back to code snippet queries related javascript