Web StyleElement API | StyleElement media property

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:
Click the button:

When the button is clicked:

Supported Browsers:

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.