Get the actual style property value of an element


/ Published in: JavaScript
Save to your folder(s)

Gets the style property as rendered, not as defined (which can be different).


Copy this code and paste it in your HTML
  1. function measure(el, styleProp) {
  2. if (el.currentStyle)
  3. var st = el.currentStyle[styleProp];
  4. else if (window.getComputedStyle)
  5.  
  6. var st = document.defaultView.getComputedStyle(el, null).getPropertyValue(styleProp);
  7. return st;
  8. }

URL: http://www.quirksmode.org/dom/getstyles.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.