Is there a way to load external CSS files, like we load JS file by using .getScript method and also use the callback function like in .getScript
$("<link/>", { rel: "stylesheet", type: "text/css", href: "/styles/yourcss.css" }).appendTo("head");
This Works in FireFox and similar but not in IE.
You mean you want to add Javascript to a CSS file? If that's the case, then you can't. Only CSS in CSS files :) You'll have to deal with some sort of master page which holds that js file.
In jQuery 1.4:
$("<link/>", { rel: "stylesheet", type: "text/css", href: "/styles/yourcss.css" }).appendTo("head");
http://api.jquery.com/jQuery/#jQuery2
Quick function based on responses.
loadCSS = function(href) { var cssLink = $("<link>"); $("head").append(cssLink); //IE hack: append before setting href cssLink.attr({ rel: "stylesheet", type: "text/css", href: href }); };
Usage:
loadCSS("/css/file.css");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With