Created
April 16, 2012 15:24
-
-
Save kavanagh/2399453 to your computer and use it in GitHub Desktop.
Append CSS Stylesheet to the head using jQuery
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
$.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