From 9ea18ee0ed0558cc7dc1ba82fb9b18e37871f960 Mon Sep 17 00:00:00 2001 From: Elias John Date: Mon, 1 Mar 2021 12:04:10 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=9Escript.js=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 5fdf7bf..625cfcb 100644 --- a/script.js +++ b/script.js @@ -1 +1,35 @@ -console.log +let darkmode = false ; +const BUTTON= Document.getElementbyId ('Switch '); +const Body = document.querySelector ('body') ; + + +if (window.matchMedia('(prefers-scheme:dark )').matches ) { +darkmode= true ; +} else{ + darkmode= false; +} + +console.log(darkmode); + +const switchMode = () => { + darkmode = !darkmode; + setclassTobody(); + +} + +const setclassTobody =() => { +if (darkmode){ + Body.classList.remove('light'); + Body.classList.add('dark'); + +}else{ + Body.classList.add('light'); + Body.classList.remove('dark'); + +} + +} ; + +BUTTON.addEventLister('click', switchMode ); +setclassTobody; +