I have a website with 2 styles, one for day and one for night reading. I have an image with an event onclickto call a function to change a stylesheet. The problem is that for new visitors, when they first click the button, the page goes into a completely uninstalled (that is, without a style sheet) only for half a second, then a new one arrives. I know the reason for this is because I delete the rel="stylesheet"current sheet before adding it to a new one. Is there a way to improve the function so that there is no short delay, even for new visitors? Thank.
function changeStyleSheet() {
var a = document.getElementById('stylesheet1');
var b = document.getElementById('stylesheet2');
var now1 = $(a).attr('rel');
var now2 = $(b).attr('rel');
if (now1 == 'stylesheet') {
a.setAttribute('rel', 'alt-stylesheet');
b.setAttribute('rel', 'stylesheet');
} else {
b.setAttribute('rel', 'alt-stylesheet');
a.setAttribute('rel', 'stylesheet');
}
};
source
share