Question: I've been tasked with creating a simple toggle button to switch between CSS sheets creating a light theme and a dark theme. I have 2

I've been tasked with creating a simple toggle button to switch between CSS sheets creating a light theme and a dark theme. I have 2 CSS sheets linked on my page, with the dark theme being disabled. I have a button with an onclick attribute calling a function.

function setTheme() {

let defTheme = document.getElementById('default'),

drkTheme = document.getElementById('dark');

if (defTheme.disabled == 'disabled') {

defTheme.disabled = undefined;

drkTheme.disabled = 'disabled';

} else {

defTheme.disabled = 'disabled';

drkTheme.disabled = undefined;

}

}

My code works to toggle the disabled CSS sheet to on - but I can not click again to disable and re-enable my default CSS sheet. What am I doing wrong? What's the simplest way to toggle between 2 CSS stylesheets with a single botton? MUST be done with a single button ***

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!