Skip to content Skip to sidebar Skip to footer

Detect Font Size In Pixels Using Jquery

How can I detect font size using jQuery? If I am using em and i need to detect font size in pixels

Size of font in pixels?

Solution 1:

http://jsfiddle.net/g9uKq/

I made you a fiddle just to be clear.

var size = $("h1").css('font-size');

Solution 2:

This should work:

parseInt($("h1").css("font-size"))

Solution 3:

Have you tried using this method?

var size = $(element).css('font-size');

Solution 4:

Try this,

functionem(input) {
 var emSize = parseFloat($("h1").css("font-size"));
 return (emSize * input);
}

Solution 5:

use css() to get the font-size... this gives the size in px... so divide it by 16 should give you the value in em. try this

var sizeinem=parseFloat($('h1').css('font-size')) / 16;
 alert(sizeinem);

fiddle here

Post a Comment for "Detect Font Size In Pixels Using Jquery"