Javascript DOM HTML Link media Property set

Introduction

Change the media type:

document.getElementById("myLink").media = "all";

Click the button to change the media type the link element is intended for.

View in separate window

<!DOCTYPE html>
<html>
<head>
<link id="myLink" rel="stylesheet" type="text/css" media="screen" href="style.css">
</head>//from  w w w .  ja va  2  s  .  c  o  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").media = "all";
  document.getElementById("demo").innerHTML = "The media type was changed.";
}
</script>

</body>
</html>



PreviousNext

Related