Getting the element position - { absolute|relative|fixed } - Javascript CSS Style Property

Javascript examples for CSS Style Property:position

Description

Getting the element position - { absolute|relative|fixed }

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

div {/*from   w  w  w.jav  a 2  s.c  om*/
   position: fixed;
}


      </style> 
      <script type="text/javascript">
    window.onload=( function() {
var div = document.getElementById("div");
console.log(div.style.position);
console.log(getComputedStyle(div).position);
    });

      </script> 
   </head> 
   <body> 
      <div id="div" style="position: absolute;"></div>  
   </body>
</html>

Related Tutorials