Im having problems with this function applying css(using a text variable) working with Internet Explorer but it works in Firefox & Chrome.
the code:
var style = document.createElement('style');
Adding new stylesheets and scripts by creating elements using DOM methods is something that has always been dicey cross-browser. This won't work in IE or WebKit.
style.rel = 'stylesheet';
style.href = 'FireFox.css';
There's no such properties on an HTMLStyleElement. contains inline code. For external stylesheets, use a . By luck, it happens this does work:
var link= document.createElement('link');
link.rel= 'stylesheet';
link.href= 'something.css';
head.appendChild(link);
But doesn't give you a convenient way to insert rules from script.
You can also add new rules to an existing stylesheet (eg. an empty style in the ) by using the document.styleSheets interface. Unfortunately, IE's interface doesn't quite match the standard here so you need code branching:
var style= document.styleSheets[0];
if ('insertRule' in style)
style.insertRule('p { margin: 0; }', 0);
else if ('addRule' in style)
style.addRule('p', 'margin: 0', 0);