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

Solution 1:

This seems to work:

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

Solution 2:

Here's a solution that doesn't require jQuery, and doesn't require an explicit font-size declaration.

window.innerWidth / parseFloat(
  getComputedStyle(
    document.querySelector('body')
  )['font-size']
)