Do you know how to code buttons
ZakMcCall (1)

Thx in advance. I need this for a light mode and a dark mode

You are viewing a single comment. View All
tussiez (1677)

Here's a button:

HTML

<button class="light_mode" onclick="alert('rick roll')">You can trust this button</button>

CSS

.light_mode button {
border: 1px solid black;
background-color: white;
color: black; /* override browser default style */
}

.dark_mode button {
border: 1px solid white;
background-color: #333;
color: white;
}

JavaScript: (toggles light/dark mode)

let currMode = 'light_mode';
const changeMode = () => {
let gr = document.getElementsByClassName(currMode);
currMode = currMode == 'light_mode' ? 'dark_mode' : 'light_mode'; // change modes
for(let ele of gr) { // iterate over each element with a specified theme
ele.setAttribute('class', currMode); // change style
}
}