Toggle div element background colour - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Toggle div element background colour

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

#demo {//from  w w  w .  j a v a  2s.  co  m
   font-family: monospace;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var div = document.querySelector('#demo');
div.style.background = 'rgb(255,0,0)';
div.innerText = div.style.background;
    }

      </script> 
   </head> 
   <body> 
      <div id="demo"></div>  
   </body>
</html>

Related Tutorials