Get element style via return value from getComputedStyle - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window getComputedStyle

Description

Get element style via return value from getComputedStyle

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

.overlay{/*from w  w  w.  ja  v a 2 s  .  c  om*/
   width: 100px;
   height: 200px;
   background-color:red;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var computedStyle = getComputedStyle(document.getElementsByClassName("overlay")[0], null)
console.log(computedStyle.width);
    }

      </script> 
   </head> 
   <body> 
      <div class="overlay">
          fdsfsd 
      </div>  
   </body>
</html>

Related Tutorials