Created
February 23, 2015 11:28
-
-
Save matijs/17638e91c9ce1cee3e04 to your computer and use it in GitHub Desktop.
load CSS using JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadCSS(href, options){ | |
'use strict'; | |
options = options || {}; | |
var styleSheet = document.createElement('link'); | |
var ref = options.before || document.getElementsByTagName('script')[0]; | |
styleSheet.media = 'not all'; | |
styleSheet.rel = 'stylesheet'; | |
styleSheet.href = href; | |
styleSheet.onload = function () { | |
styleSheet.onload = null; // only run once | |
styleSheet.media = options.media || 'all'; | |
if (typeof(options.callback) === 'function') { | |
options.callback(); | |
} | |
}; | |
ref.parentNode.insertBefore(styleSheet, ref); | |
return styleSheet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on https://github.com/filamentgroup/loadcss