Open In App

HTML DOM Link media Property

The HTML DOM link media property is used to set or return the value of the media attribute of an <link> element. The media attribute is used to specify what type of media devices the target resource is optimized. 

Syntax:



It is used to return the media property.

linkObject.media; 

It is used to set the media property.



linkObject.media="values" 

Property values:

Return Value: It returns a String value which represents media types comma-separated list.

Example: Below HTML code illustrates, how to return the link media property. 




<!DOCTYPE html>
<html>
<head>
    <link id="linkid" rel="stylesheet"
        type="text/css" href="" media="screen">
</head>
 
<body style="text-align:center;">
    <h1>GeeksforGeeks</h1>
    <h2>DOM Link media Property</h2>
    <button onclick="btnclick()">Return</button>
    <p id="pid" style="font-size:25px;color:green;">
    </p>
 
    <script>
        function btnclick() {
             
            // return Link media Property
            var newVar = document
                .getElementById("linkid").media;
 
            document.getElementById(
                "pid").innerHTML = newVar;
        }
    </script>
</body>
</html>

Output:

Supported Browsers:


Article Tags :