Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Created July 5, 2013 12:17
Show Gist options
  • Save jswhisperer/5934160 to your computer and use it in GitHub Desktop.
Save jswhisperer/5934160 to your computer and use it in GitHub Desktop.
Create a stylesheet with JS
var sheet = (function() {
// Create the <style> tag
var style = document.createElement("style");
// Add a media (and/or media query) here if you'd like!
// style.setAttribute("media", "screen")
// style.setAttribute("media", "@media only screen and (max-width : 1024px)")
// WebKit hack :(
style.appendChild(document.createTextNode(""));
// Add the <style> element to the page
document.head.appendChild(style);
return style.sheet;
})();
sheet.addRule("#myList li", "float: left; background: red !important;", 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment