Classlist.remove und .add funktionieren aus irgendeinem Grund nichtHTML

HTML-Programmierer
Anonymous
 Classlist.remove und .add funktionieren aus irgendeinem Grund nicht

Post by Anonymous »

Beim Umschalten des Schalters erhalte ich diese Fehler aus der Browserkonsole. Aus irgendeinem Grund funktioniert es nicht und ich kann nicht lösen, warum dies nicht funktioniert.

Code: Select all

Uncaught TypeError: Cannot read properties of undefined (reading 'remove')
at getValue (darkModeSwitch.js:8)
at window.onload (index.html:17)

Uncaught TypeError: Cannot read properties of undefined (reading 'add')
at getValue (darkModeSwitch.js:13)
at HTMLInputElement.onclick (index.html:26)
< /code>


const body = document.body
const anchor = document.getElementsByTagName("a");
const darkModeToggle = document.getElementById('darkModeToggle');

function getValue(){
if (darkModeToggle.checked) {
body.classList.remove("lightmode")
anchor.classList.remove("lightmode")
console.log("checked")
} else{
console.log("not checked")
body.classList.add("lightmode")
anchor.classList.add("lightmode")
}
};< /code>
.lightmode{
background-color: white;
color: black;
}< /code>

[list]
[*][url=kapcsolat/kapcsolat.html?version=691]Kapcsolat[/url]
[*][url=projects/projects.html?version=691]Projektek
[*]Kezdőlap[/url]
[*]

[url=index.html?version=-23424893215]jayden.hu[/url]
[/list]

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post