title: How can you measure the space that a text will take in Javascript?
body: <p>In Javascript, I have a certain string, and I would like to somehow measure how much space (in pixels) it will take within a certain element.</p>
  
  <p>Basically what I have is an element that will float above everything else (like a tooltip), and I need to set its width manually through Javascript, so it will adjust to the text inside.<br>
  I can't have it "auto-grow" naturally like an inline element would grow horizontally to contain its children.</p>
  
  <p>In Windows there are APIs that do this. Is there a way to do the same thing in Javascript?<br>
  If there is no decent way, what approach do you believe is feasible?
  (Like, trying out different widths and checking the height to make sure it didn't go over a certain threshold).</p>
  
  <p>The less "pixel values" I can hardcode in my JS the better, obviously.</p>