Javascript DOM HTML Link href Property set

Introduction

Change style sheet:

Click the button to change the value of the href attribute of the linked document.

This will change the style sheet.

View in separate window

<!DOCTYPE html>
<html>
<head>
<link id="myLink" rel="stylesheet" type="text/css" href="style2.css">
</head>//from   w  w w. j a  va 2  s. co m
<body>

<h1>I am formatted with a linked style sheet</h1>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("myLink").href = "style.css";
}
</script>

</body>
</html>



PreviousNext

Related