how to set href value of anchor tag in javascript

Created at 17-Nov-2020, By samar

how to set href value of anchor tag in javascript

We’ll attempt to use programming in this lesson to solve the "how to set href value of anchor tag in javascript" puzzle.

  • <a id="myAnchor"> Anchor tag </a>
    <script>
       document.getElementById("myAnchor").href = "https://www.cnn.com/";
       let hrefVal = document.getElementById("myAnchor").href ;
       document.write(hrefVal);
    </script>
    
    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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.