Your Ad Here

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.