Latest web development tutorials

HTML DOM Link href attribute

Link Object Reference Link Objects

Definition and Usage

href attribute is a readable and writable string sets or returns the complete URL of the document currently displayed.

grammar

Set the href attribute:

linkObject.href="URL"

Back href attribute:

linkObject.href


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support href attribute


Examples

Examples

Click on a button to switch style sheets:

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Link id = "style1" rel = "stylesheet" type = "text / css" href = "style1.css">
<Script>
function displayResult () {
document.getElementById ( "style1") href = "style2.css".;
}
</ Script>
</ Head>
<Body>

<H1> My Home Page </ h1>
<Button type = "button" onclick = "displayResult ()"> to switch style sheets </ button>

</ Body>
</ Html>

try it"


Link Object Reference Link Objects