Open In App

Web StyleElement API | StyleElement media property

Last Updated : 31 Jul, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

In Web API there are style elements which have media attribute. To fetch this media attribute we use HTMLStyleElement.media property, which specifies the intended destination medium for style information.

Syntax:

label = style.media
style.media = label

label is a string which describes a single medium or a comma-separated list.

Example: get the media attribute




<!DOCTYPE html>
<html>
  
<head>
    <title>
      StyleElement media property
  </title>
    <style>
        a:focus {
            background-color: magenta;
        }
    </style>
    <link id="Link" 
          rel="stylesheet"
          type="text/css"
          media="screen" />
    
    <script type="text/javascript">
        function getmedia() {
            var label = document.getElementById('Link');
  
            document.getElementById(
              'media').innerHTML = label.media;
        }
    </script>
  
</head>
  
<body>
    <center>
  
        <h1 style="color:green;">  
                GeeksForGeeks  
            </h1>
  
        <h2>HTML StyleElement media property</h2>
        <button onclick="getmedia();"
                id="btn">Get media</button>
        <p id='media'></p>
    </center>
</body>
  
</html>


Output:
Click the button:

When the button is clicked:

Supported Browsers:

  • Google Chrome
  • Edge 12
  • Internet Explorer
  • Firefox
  • Safari
  • Opera


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads