Returns the set of media constraints applied to the stylesheet

Description

media returns the set of media constraints applied to the stylesheet in type of MediaList.

Example


<!DOCTYPE HTML> 
<html> 
<head> 
    <style title="core styles"> 
        p { <!--from  w ww  .j  av a  2 s  . com-->
            border: medium double black; 
            background-color: lightgray; 
        } 
        #block1 { color: white;} 
    </style> 
    <link rel="stylesheet" type="text/css" href="styles.css"/> 
    <style media="screen AND (min-width:500px), PRINT" type="text/css"> 
        #block2 {color:yellow; font-style:italic} 
    </style> 
</head> 
<body> 
    <p id="block1">
        This is a test. 
    </p> 
    <p id="block2"> 
        This is a test. 
    </p> 
    <div id="placeholder"/> 
    <script> 
        var placeholder = document.getElementById("placeholder"); 
        var sheets = document.styleSheets; 
        for (var i = 0; i < sheets.length; i++) { 
            if (sheets[i].media.length > 0) { 
                var newElem = document.createElement("table"); 
                newElem.setAttribute("border", "1"); 
                newElem.innerHTML += "<tr><td>Media Count:</td><td>" + 
                                     sheets[i].media.length + 
                                     "</td></tr>"; 
                newElem.innerHTML += "<tr><td>Media Text:</td><td>" + 
                                     sheets[i].media.mediaText + 
                                     "</td></tr>";                     
                            
                for (var j =0; j < sheets[i].media.length; j++) { 
                    newElem.innerHTML += "<tr><td>Media " + j+ 
                                         "</td><td>" + 
                                         sheets[i].media.item(j) + 
                                         "</td></tr>";                     
                } 
                placeholder.appendChild(newElem); 
            } 
        } 
    </script> 
</body> 
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window