In this example, I’ll show you How to find the value of the href attribute of a link in javascript.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<!DOCTYPE html> <html> <body> <p><a id="myAnchor" href="https://www.code4examples.com/">C4E</a></p> <p>Click the button to display the value of the href attribute of the link above.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myAnchor").href; document.getElementById("demo").innerHTML = x; } </script> </body> </html> |
Output: