jQuery Style How to - Get font-size








Question

We would like to know how to get font-size.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
#test {<!--from  www  .  j  a  v  a  2s.c o  m-->
  font-size: 2.45em;
}

#test2 {
  font-size: 2.4em;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    var a = $("#test").css('font-size');
    var b = $("#test2").css('font-size');
    console.log("test  = " + a + "\ntest2 = " + b);
});
</script>
</head>
<body>
  <div id="test">TEXT</div>
  <div id="test2">TEXT2</div>
</body>
</html>

The code above is rendered as follows: