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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#