Anchor href Property
Example
Change the destination (URL) of a link:
document.getElementById("myAnchor").href = "jsref_arrays";
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
The href attribute is an HTML4 feature.
It has been supported in all browsers since 1997.
| Chrome | Edge | Firefox | Safari | Opera | IE |
| Yes | Yes | Yes | Yes | Yes | 11 |
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
Get the URL of a link:
let text = document.getElementById("myAnchor").href;
Try it Yourself »
Example
Get the text of a link:
let text = document.getElementById("myAnchor").innerHTML;
Try it Yourself »
Related Pages
HTML reference: HTML <a> href attribute
❮ Anchor Object