title: Javascript. Can't get element style
body: <p>I'm trying to get width &amp; height of the img element. It gives 0px whatever I do.</p>
  
  <pre><code>function foo(element){
  if(element){
      var el=document.querySelector(element);
      var img=el.getElementsByTagName("img")[0];
      alert(img.style.width);
  }
  }
  foo();
  </code></pre>
  
  <p>And the html:</p>
  
  <pre><code>&lt;div id="theid" class="theclass"&gt;
     &lt;img id="img" alt="img" name="the img" src="img/img.jpg" /&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  foo("#theid");
  &lt;/script&gt;
  </code></pre>
  
  <p>I've also tried <code>.offsetWidth</code>, <code>.clientWidth</code> and <code>defaultView.getComputedStyle(img,"");</code></p>