HTML DOM Link href attribute
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
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>
<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 Objects