An implementation of $.getScript but for stylesheets. Call it $.getStylesheet
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($) { | |
$.getStylesheet = function (href) { | |
var $d = $.Deferred(); | |
var $link = $('<link/>', { | |
rel: 'stylesheet', | |
type: 'text/css', | |
href: href | |
}).appendTo('head'); | |
$d.resolve($link); | |
return $d.promise(); | |
}; | |
})(jQuery); |
It always callbacks done/then(), no matter the href is loaded or broken.
And it callbacks when the
I modified to make it works like $.getScript to fit my needs.
(function($) {
$.getStylesheet = function (href) {
return $.ajax({
dataType: "text",
url: href,
}).done( function(text){
$("<style>").html(text).appendTo("head");
} );
};
})(jQuery);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excelent thanks!