0

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"});
});

});

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.