Trying to do a dark-mode toggle on click of element
- toggle div class = .dark__mode
- css link class = .css-link
- css link href variable = style__old
I am learning jquery and i think there is a major problem with reasoning and structure of code
The link href changes at first but doesn't change back
Please help and or if using a checkbox option is better
window.onload = function(){
var style__old = $(".css-link").attr("href");
$(".dark__mode").click(function(){
if (style__old == "css/style.css"){
var style__new = style__old.replace("style.css","dark-mode.css");
$(".css-link").attr("href", style__new);
}
else
if (style__old == "css/dark-mode.css"){
style__old.replace("dark-mode.css","style.css");
$(".css-link").attr("href", "style__old");
}
}
);}