Javascript DOM HTML Link media Property get

Introduction

Return the media type the link element is intended for:

var x = document.getElementById("myLink").media;

Click the button to return 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  www .java2 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() {
  var x = document.getElementById("myLink").media;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The media property sets or gets the media type for the link element.

The style might be different for computers and mobile devices.

The media property accepts and returns a String type value.

Value Description
allall devices. Default
aural speech synthesizers
brailleBraille tactile feedback devices
embossed paged Braille printers
handheld handheld devices
print printed pages and print preview
projection projectors or transparencies
screen color computer screens
speech speech synthesizers
ttyteletype devices
tv TV-type devices

The media property return a String representing a comma-separated list of media types.




PreviousNext

Related