Posted By

szsk on 08/24/06


Tagged

css javascript ie DOM Opera Firefox


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

shachi
vali29


addStylesheetRule


 / Published in: JavaScript
 

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

  1. function addRule( selector, property, sheetindex, ruleindex ) {
  2. if( sheetindex == undefined ) sheetindex = 0;
  3. var sheet = document.styleSheets[ sheetindex ];
  4.  
  5. if( sheet.addRule ) { //IE
  6. if( ruleindex == undefined ) ruleindex = sheet.rules.length;
  7. sheet.addRule( selector, "{" + property + "}", ruleindex );
  8. return ruleindex;
  9. }
  10. else if( sheet.insertRule ) { //Mozilla
  11. if( ruleindex == undefined ) ruleindex = sheet.cssRules.length;
  12. return sheet.insertRule( selector + "{" + property + "}", ruleindex );
  13. }
  14.  
  15. return null;
  16. }

Report this snippet  

You need to login to post a comment.