Posted By

szsk on 08/24/06


Tagged

css javascript ie DOM Opera Firefox


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

shachi
vali29
Knarf


getStyleValue


 / Published in: JavaScript
 

URL: http://bmky.net/text/note/javascript-css.html

  1. function getStyleValue( selector, property, sheetindex ) {
  2. selector = selector.toLowerCase( )
  3. if( sheetindex == undefined ) sheetindex = 0;
  4. if( property.indexOf( "-" ) != -1 ) property = property.camelize( );
  5. var rules = document.styleSheets[ sheetindex ].rules //IE
  6. || document.styleSheets[ sheetindex ].cssRules; //Mozilla
  7.  
  8. for( var i = rules.length - 1; i >= 0; i-- ) {
  9. var rule = rules[i];
  10. if( rule.selectorText.toLowerCase( ) != selector
  11. || rule.style[ property ] == "" ) continue;
  12. return rule.style[ property ];
  13. }
  14.  
  15. return null;
  16. }

Report this snippet  

You need to login to post a comment.