Allows you to accurately obtain an element’s em value in pixels using JavaScript.
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Latest commit d744db5 Oct 4, 2016
Permalink
Failed to load latest commit information.
.gitattributes Adding to GitHub Jun 24, 2013
.gitignore Adding to GitHub Jun 24, 2013
README.md Adding links Jun 24, 2013
bower.json Create bower.json Feb 26, 2016
getEmPixels.js Adding to GitHub Jun 24, 2013
getEmPixels.min.js Adding to GitHub Jun 24, 2013

README.md

GetEmPixels

Allows you to accurately obtain an element’s em value in pixels using JavaScript. No more blindly dividing by hard-coded values.

Demo: http://www.matanich.com/examples/get-em-pixels/

Article: http://www.matanich.com/2013/06/24/em-values-javascript/

The basics

GetEmPixels is simple to use and has only one function.

// Get the em or rem value of the documentElement
getEmPixels();

// Get the em value of the #footer element
getEmPixels(document.getElementById('footer'));

Size and delivery

Currently, getEmPixels.js compresses to around 481 bytes (~0.47 KB) after minify. To minify, you might try these online tools: [Microsoft Ajax Minifier]:(http://ajaxmin.codeplex.com/), [Uglify]:(http://marijnhaverbeke.nl/uglifyjs), [Yahoo Compressor]:(http://refresh-sf.com/yui/), or Closure Compiler.

Support

GetEmPixels supports a broad range of browsers and devices (there are currently no known unsupported browsers).