Javascript examples for DOM HTML Element:Anchor
The href property sets or gets the value of the href attribute of a link.
Value | Description |
---|---|
URL | Sets the URL of the link. |
Possible values for href property:
A String, representing the entire URL of the link, including the protocol, like http://
The following code shows how to Change the destination (URL) of a link:
<!DOCTYPE html> <html> <body> <p><a id="myAnchor" href="http://www.microsoft.com">www.microsoft.com</a></p> <button onclick="myFunction()">change the value of the href attribute of the link</button> <p id="demo"></p> <script> function myFunction() {/*ww w . j a va2 s .c o m*/ document.getElementById("myAnchor").href = "http://www.cnn.com/"; document.getElementById("demo").innerHTML = "The link above now goes to www.cnn.com."; } </script> </body> </html>