View Single Post
Old 10-14-2012, 04:49 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
There's a little problem with the computed style of font sizes, though - while IE will return the font size in the measurements in the css (in this case in em) firefox and Chrome actually compute its size and return that in px

Not that I'm offering a solution or anything. Just thought I'd point that out

Code:
<html>
<head>
<style type="text/css">
#foo {font-size:1em;}
</style>

</head>
<body>
<div id="foo">hello</div>
<script type="text/javascript">


function getStyle(el, cssprop){
 if (el.currentStyle) //IE
  return el.currentStyle[cssprop]
 else if (document.defaultView && document.defaultView.getComputedStyle) //Firefox
  return document.defaultView.getComputedStyle(el, "")[cssprop]
 else //try and get inline style
  return el.style[cssprop]
}


var bar = document.getElementById("foo");
bar.style.fontSize = "4em" 
alert(getStyle(bar, "fontSize")); // displays in px in FF and Chrome, in em in IE
</script>
</body>
</html>
xelawho is offline   Reply With Quote