title: Javascript positioning center style
body: <p>I wanted to set my second div element indside of my first div element center. I think somehow I managed to center it. But I think I made some mistakes and it seems to me it is not properly centered and also this JavaScript style seems to me bad. Is there any better way doing it? Is my JavaScript code is correct?</p>
  
  <p><a href="http://jsfiddle.net/2dGn4/7/" rel="nofollow">FIDDLE</a></p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;div class='first'&gt;
      &lt;div class='second'&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JavaScript</strong></p>
  
  <pre><code>var first = document.getElementsByClassName('first')[0];
  var second = document.getElementsByClassName('second')[0];
  var height = first.offsetHeight;
  second.style.width = height/2+"px";
  second.style.height = height/2+"px";
  second.style.marginLeft = height/4+"px";
  second.style.marginTop = height/4+"px";
  </code></pre>