Link hrefProperty
Link Object
Definition and Usage
The href property is a readable and writable string that sets or returns the full URL of the currently displayed document.
Syntax
Set the href property:
linkObject.href="URL.html"
Return the href property:
linkObject.href
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the href property.
Example
Example
Switch stylesheet by clicking a button:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<link id="style1" rel="stylesheet" type="text/css" href="style1.css.html">
<script>
function displayResult(){
document.getElementById("style1").href="style2.css.html";
}
</script>
</head>
<body>
<h1>My Website Homepage</h1>
<button type="button" onclick="displayResult()">Switch stylesheet</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<link id="style1" rel="stylesheet" type="text/css" href="style1.css.html">
<script>
function displayResult(){
document.getElementById("style1").href="style2.css.html";
}
</script>
</head>
<body>
<h1>My Website Homepage</h1>
<button type="button" onclick="displayResult()">Switch stylesheet</button>
</body>
</html>
Try it Yourself »
Link Object Other Extensions