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);
精彩评论