Easy Tutorial
❮ Jsref Log Prop Checkbox Form ❯

Link href Attribute


Definition and Usage

The href attribute is a read-write string that can set or return the complete URL of the currently displayed document.

Syntax

Setting the href attribute:

Returning the href attribute:


Browser Support

All major browsers support the href attribute.


Example

Switching stylesheets when a button is clicked:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</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 Website Homepage</h1>
<button type="button" onclick="displayResult()">Switch Stylesheet</button>

</body>
</html>

❮ Jsref Log Prop Checkbox Form ❯