You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Linksseite/Darkmode.js

36 lines
595 B
JavaScript

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;