I need to use insertRule to modify some CSS via Javascript. I also need to support IE7-8, so I need some way to differentiate in Javascript whether I should use insertRule or addRule (without browser sniffing).
This is what I’m trying and it does not work:
var sheets = document.styleSheets
if(sheets.insertRule) {
alert("insert");
// insert
} else {
alert("add");
// add
}
Any idea if this is possible and how to get it to work?
EDIT:
If I run this in IE8, I get an error on the page object does not support this property or method
There seem to be no bugs in IE8, as evidenced by this test run.
The problem is probably due to the fact that the code you have replaced with comments calls methods that are undefined.