Skip to content

Instantly share code, notes, and snippets.

@kavanagh
Created April 16, 2012 15:24
Show Gist options
  • Save kavanagh/2399453 to your computer and use it in GitHub Desktop.
Save kavanagh/2399453 to your computer and use it in GitHub Desktop.
Append CSS Stylesheet to the head using jQuery
$.appendStylesheet = function appendStylesheet(url, callback) {
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = url;
link.rel = "stylesheet";
link.type = "text/css";
if (callback && $.isFunction(callback)) {
if ($.browser.msie) {
link.onreadystatechange = function () {
if (link.readyState == 'complete') {
callback();
}
}
} else {
link.onload = callback;
}
}
head && head.appendChild(link);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment