Css Injector by Javascript (CoffeeScript)
When you need make css preview online you can use that
coffeescript function code cod
cssStyleInjector = (cssText, id="default", elem="head") ->
thisCss = document.getElementById(id)
return thisCss.innerHTML = cssText if thisCss?
css = document.createElement("style")
css.setAttribute "type", "text/css"
css.setAttribute "id", id
style = document.createTextNode(cssText)
css.appendChild style
document[elem].appendChild css
javascript function code
var cssStyleInjector;
cssStyleInjector = function(cssText, id, elem) {
var css, style, thisCss;
if (id == null) { id = "default"; }
if (elem == null) { elem = "head"; }
thisCss = document.getElementById(id);
if (thisCss != null) { return thisCss.innerHTML = cssText; }
css = document.createElement("style");
css.setAttribute("type", "text/css");
css.setAttribute("id", id);
style = document.createTextNode(cssText);
css.appendChild(style);
return document[elem].appendChild(css);
};
Written by Pawel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
iam4x
94.17K
ericdfields
63.02K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#