- 1
Button problems
I want to make a button that turns something on and when you press it again it turns that thing off. Can someone do a simple code to show how to do it please?
3 Answers
+ 1
// Or
const ro = document.querySelector(".ro");
const txt = document.querySelector(".txt");
toggle = () => {
ro.classList.toggle("ro-on");
txt.innerText = ro.classList.contains("ro-on") ? "Turn something off" : "Turn something on";
}
0
If you don't understand then ask here