So I have 2 css files - light.css and dark.css.
I have a button on a page which toggles the <link>
element's 'href' attribute between these two css files.
Now, I have a <div>
which gets its background styling from light.css by default. Upon changing the 'href' attribute to 'dark.css', the div doesn't take on the new styling code provided in the dark.css...
Any ideas why?
== EDIT: Added code snippets...
The JS to change the <link>
:
var nightMode = false;
var theme = document.querySelector('#theme');
// Where <link id="theme" style="text/css" rel="stylesheet" href="light.css">
function toggleNight()
{
if (!nightMode)
{
setTimeout("theme.setAttribute('href', '_css/dark.css')", 400);
nightMode = true;
}
else
{
setTimeout("theme.setAttribute('href', '_css/light.css')", 400);
nightMode = false;
}
}
In addition to this, the CSS files look like this:
// light.css
div{background:#ddd;}
// dark.css
div{background:#333;}