Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2011
    Location
    Algeirs,Algeria
    Posts
    43
    Thanks
    5
    Thanked 3 Times in 3 Posts

    Are style elements counted in document.styleSheets array?

    I have one question about <style> elements, are they counted in document.styleSheets array? and can I add rules to them by using insertRule() and deleteRule() methods?
    Last edited by Hamza7; 07-17-2011 at 02:53 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,395
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Generally speaking ... yes

    But: As always IE is cooking for a different party ... the methods are called addRule and removeRule there.

    Normal browsers
    Code:
    var myrules = document.styleSheets[0].cssRules;  // all the rules
    var myStyle = document.styleSheets[1];
    myStyle.insertRule(...);
    IE
    Code:
    var myrules = document.styleSheets[0].rules;  // all the rules
    var myStyle = document.styleSheets[1];
    myStyle.addRule(...);

  • #3
    New Coder
    Join Date
    Jun 2011
    Location
    Algeirs,Algeria
    Posts
    43
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Thanks, I knew that IE use addRule() and removeRule(), but I am working on a script that works on FireFox, so I don't have to target IE.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •