Is it possible to get the width of the window in em units using javascript?

hammerbrostime picture hammerbrostime · Sep 3, 2012 · Viewed 25.8k times · Source

I'm looking for a reliable way to get the width of the window in em units using javascript. I was surprised to see that jQuery will only return a result in pixel measurements. Any help is appreciated.

Answer

hammerbrostime picture hammerbrostime · Sep 3, 2012

This seems to work:

$(window).width() / parseFloat($("body").css("font-size"));