Javascript Style How to - Return the style properties for width


We would like to know how to return the style properties for width.


<!DOCTYPE html>
<style type='text/css'>
#foo {<!--from   w  w w.java2s.  c  o m-->
  background: green;
  width: 80px;
<script type='text/javascript'>
function getWidth() {
    var elem = document.getElementById("foo");
    var theCSSprop = window.getComputedStyle(elem, null).getPropertyValue("width");

  <div id="foo" onClick="getWidth()">Hello World. click and check the console.</div>

The code above is rendered as follows: