JSFiddle - React, Tailwind, and code Playground
HTML
<div id="application_osx">foo</div>
JavaScript
var StyleWriter = new Class({
// css classes on the fly, based on by Aaaron Newton's version
createStyle: function(css, id) {
try {
if ($(id) && id) return;
var style = new Element('style', {id: id||'',type:'text/css'}).inject(document.getElement('head'));
if (window.ie)
style.styleSheet.cssText = css;
else
style.setHTML(css);
} catch(e) {
console.log("failed:", e.message);
}
}
});
var rules = [
"#application_osx { background: red url(/path/to/image/application_osx.png) }",
"#someotherid { background: url(/path/to/image/someotherid.png) }"
];
// direct use through class
(function() {
new StyleWriter().createStyle(rules.join("\n"), "mystyles");
}).delay(2000); // wait 2 sec then add css rules