Anchor href Property
Example
Change the destination (URL) of a link:
document.getElementById("myAnchor").href = "http://www.cnn.com/";
Try it Yourself »
Description
The href property sets or returns the value of the href attribute of a link.
The href attribute specifies the destination of a link.
Browser Support
Property | |||||
---|---|---|---|---|---|
href | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the href property:
anchorObject.href
Set the href property:
anchorObject.href = URL
Property Values
Value | Description |
---|---|
URL |
Specifies the URL of the link. Possible values:
|
Technical Details
Return Value: | A String, representing the URL of the link. Returns the entire URL, including the protocol (like http://) |
---|
More Examples
Example
Another example of how to get the URL of a link (a relative URL):
var x =
document.getElementById("myAnchor").href;
Try it Yourself »
Related Pages
HTML reference: HTML <a> href attribute
❮ Anchor Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.