I am having a problem adding a dynamic style element with @import statements for IE. Try the following:
var string = '@import url(test.css)';
var style = document.createElement('style');
if (style.styleSheet) {
style.styleSheet.cssText = string;
} else {
var cssText = document.createTextNode(string);
style.appendChild(cssText);
}
document.getElementsByTagName('head')[0].appendChild(style);
This works for FF / Chrome, but not for IE. It seems to recognize style.styleSheets.importsbut will not apply the imported stylesheet. Is this a mistake or limitation?
David source
share