Converting read values in JavaScript

The getComputedStyles function doesn't obtain exactly the values that were set in the CSS. It converts them to absolute values, usually pixels.

Let's look at an example. Let's set the width as a percentage:

#elem { width: 100%; }

However, when reading the width, we will get the value not in percentage, but in pixels:

console.log(computedStyle.width); // the value in px

em

The element has the following styles:

#elem { font-size: 2em; }

Display the element's font size on button click.

enru