开发者

A simple question.Is there a way to load css link with jquery dynamic?In $.ajax or something else?

I can use jquery load lots of thing with ajax ,like script,html,xml,json

But I wonder 开发者_如何学JAVAis it possible to load or remove css file or link with jquery ?When I want change website's theme.

If it is possible ,could any body tell how to do it exactly?Or is there a tutorial?

Thank you:)


Yes, it's fairly straightforward once you know how.

$('head').append('<link rel="stylsheet" href="my-style.css" />');

Or:

$('link[href="my-style.css"]').remove();


Alternatively:

$("link").remove(); // remove all stylesheet links

// now add your new stylesheets
var styleLnk = document.createElement('link');
  styleLnk.setAttribute("type","text/css");
  styleLnk.setAttribute("href", "/myNewStyle.css");
  styleLnk.setAttribute("rel", "stylesheet");

// add stylesheet to DOM
$("head").append(styleLnk);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜