Link media Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Link

Description

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

Set the media property with the following Values

Value Description
allall devices. This is 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

Return Value

A String, representing a comma-separated list of media types

The following code shows how to return the media type the link element is intended for:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<link id="myLink" rel="stylesheet" type="text/css" media="screen" href="styles.css">
</head>/* w w w.  j a v a  2s.  c  om*/
<body>

<h1>I am formatted with a linked style sheet</h1>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
    var v = document.getElementById("myLink").media;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials