Convert px value returned by getComputedStyle to em

I devised the below snippet to do this. Any improvement suggestions?

  Array.prototype.forEach.call(document.getElementsByTagName("p"), function(el){
             console.log(el.innerHTML + ": ", ((+(getComputedStyle(el).fontSize.replace(/px/ig, "")))*0.0625).toPrecision(3) + "em");
    });


Source: javascript

Leave a Reply