开发者

change one stylesheet out of multiple using jquery

I have multiple stylesh开发者_开发知识库eet put only want to change out one (lets call it dark.css) for another (lets call it light.css); without effecting any of the others. I know jQuery will change out a current stylesheet for another fairly easily, but I can't seem to figure out how just change the one stylesheet.

Currently working with something like this:

$(".dark-button").click(function() {
$("link[rel=stylesheet]").attr({href : "dark.css"});
});

// light
$(".light-button").click(function() {
$("link[rel=stylesheet]").attr({href : "light.css"});
});

});


the best way to do it is probably assign an id to the <link> tag of the stylesheet you want to change. something like

$('#stylesheet').attr('href', 'style.css');

or you could add it dynamically, like so

$('.dark-button').click(function(){
    $('head').append("<link rel='stylesheet' type='text/css' href='dark.css'/>");
});

and do the same thing for the light button

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜