X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Link href Property

Link Object Reference Link Object

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

Internet Explorer Firefox Opera Google Chrome Safari

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:
  • An absolute URL - points to another web site (like href="http://www.example.com/default.htm")
  • A relative URL - points to a file within a web site (like href="default.htm")

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 Reference Link Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook