Generating CSS media queries with javascript - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Style

Description

Generating CSS media queries with javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">

p {//from www . ja v a2  s .co  m
   color: blue;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
document.querySelector('style').textContent += "@media screen and (min-width:400px) { div { color: red; } }";
    }

      </script> 
   </head> 
   <body> 
      <p>blue</p> 
      <div>
         red
      </div>  
   </body>
</html>

Related Tutorials