title: Measure ex in px in Javascript
body: <h2>What I want to do</h2>
  
  <p>I would like to <em>measure</em> the 1ex in px.</p>
  
  <h2>What I have learned</h2>
  
  <ul>
  <li>1ex is a <strong>relative</strong> unit -- equal to the height of lower case "x" of the font in use:</li>
  </ul>
  
  <p>An instructive image describing the situation:</p>
  
  <p><img src="https://i.stack.imgur.com/j1DqI.png" alt="enter image description here"></p>
  
  <p>link to CSS spec:</p>
  
  <p><a href="http://www.w3.org/TR/css3-values/#font-relative-lengths" rel="nofollow noreferrer">http://www.w3.org/TR/css3-values/#font-relative-lengths</a></p>
  
  <ul>
  <li><p><code>window.getComputedStyle('foo',null).height</code> or <code>jQuery('#foo').height()</code> does not help -- because they return the height of its <em>bounding box</em>.  e.g.</p>
  
  <pre><code>&lt;div id="upper"&gt; X &lt;/div&gt;
  &lt;div id="lower"&gt; x &lt;/div&gt;
  &lt;script&gt;
     var upper = $('#upper').height();
     var lower = $('#lower').height();
     console.log(upper === lower);
  &lt;/script&gt;
  </code></pre>
  
  <p>The last line gives <code>true</code>.</p></li>
  <li><p>Related pages, but not fully informative to me:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/10305993/jquery-javascript-convert-pixels-to-em-in-a-easy-way">jQuery/JavaScript: convert pixels to em in a easy way</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/5910004/how-do-i-get-a-computed-style?lq=1">How do I get a computed style?</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/12470954/javascript-convert-ex-to-px">JavaScript: convert ex to px</a></p></li>
  </ul></li>
  </ul>
  
  <p>Any information is appreciated!</p>
  
  <p>EDIT:</p>
  
  <p>Some people suggests that this is a dupe of </p>
  
  <p><a href="https://stackoverflow.com/questions/12470954/javascript-convert-ex-to-px">JavaScript: convert ex to px</a></p>
  
  <p>but there are <strong>NO ACTUAL answers</strong>:  The first answer explains only <em>relativity</em> of <code>1ex</code> and the second one is even <strong>wrong</strong> -- <code>document.getElementById('upper').style.height</code> returns <code>"" // empty char</code>.  </p>