VikingGoat
VikingGoat

Reputation: 477

change one stylesheet out of multiple using jquery

I have multiple stylesheet 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"});
});

});

Upvotes: 0

Views: 519

Answers (1)

heymrcarter
heymrcarter

Reputation: 678

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

Upvotes: 1

Related Questions