Link href Property
Example
Return the URL of the linked document:
var x = document.getElementById("myLink").href;
The result of x will be:
http://www.w3schools.com/jsref/styles.css
Try it Yourself »
Definition and Usage
The href property sets or returns the URL of a linked document.
Browser Support
![]()
The href property is supported in all major browsers.
Syntax
Return the href property:
linkObject.href
Set the href property:
linkObject.href=URL
Property Values
| Value | Description |
|---|---|
| URL |
Specifies the URL of the linked resource/document Possible values:
|
Technical Details
| Return Value: | A String, representing the URL of the linked document. Returns the entire URL, including the protocol (like http://) |
|---|
More Examples
Example
Change style sheet:
document.getElementById("myLink").href = "style2.css";
Try it Yourself »
Related Pages
HTML reference: HTML <link> href attribute
Link Object

