views:

259

answers:

2

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.

+2  A: 
$("head").append("<link>");
var css = $("head").children(":last");
css.attr({
      rel:  "stylesheet",
      type: "text/css",
      href: "address_of_your_css"
});
Raul Agrait
Ok, but how to use callback function like .getScript() once the CSS file is loaded
Starx
@Starx Please edit your original question to reflect exactly what you need - not only the loading of external CSS files dynamically, but also a callback.
Raul Agrait
+4  A: 

In jQuery 1.4:

$("<link/>", {
   rel: "stylesheet",
   type: "text/css",
   href: "/styles/yourcss.css"
}).appendTo("head");

http://api.jquery.com/jQuery/#jQuery2

RedWolves
Ok, but how to use callback function like .getScript() once the CSS file is loaded
Starx
and this is compatible in IE
Starx