From c80427fd8d0ebba64f4b7b712bc7cf4aae55a3ce Mon Sep 17 00:00:00 2001 From: Tyler Porter Date: Fri, 3 May 2019 01:21:48 +0000 Subject: [PATCH] Fixed bug with switch button on first click --- script.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/script.js b/script.js index bfa4be2..4f64f80 100644 --- a/script.js +++ b/script.js @@ -1,8 +1,4 @@ document.getElementById('switch').addEventListener('click', function() { - const stylesheet = document.getElementById('stylesheet') - if (stylesheet.getAttribute('href') === 'dist/dark.min.css') { - stylesheet.setAttribute('href', 'dist/light.min.css') - } else { - stylesheet.setAttribute('href', 'dist/dark.min.css') - } -}) \ No newline at end of file + const stylesheet = document.getElementById('stylesheet'); + stylesheet.href = stylesheet.href.replace(/dark|light/, function(replaced) { return replaced === 'dark' ? 'light' : 'dark' }); +}); \ No newline at end of file