We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

indianocean on 06/25/07


Tagged

css


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

alvaroisorna
basicmagic


Reading the style of an element


Published in: JavaScript 


Reading the style of an element in your document isn't as simple as it should be. Here a solution. Background information here: http://www.oreillynet.com/pub/a/javascript/excerpt/JSDHTMLCkbk_chap5/index5.html Script from here: http://www.quirksmode.org/dom/getstyles.html

  1. function getStyle(el,styleProp)
  2. {
  3. var x = document.getElementById(el);
  4. if (x.currentStyle)
  5. var y = x.currentStyle[styleProp];
  6. else if (window.getComputedStyle)
  7. var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
  8. return y;
  9. }

Report this snippet 

You need to login to post a comment.