- 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?

31st Mar 2022, 3:24 PM
Spencer Pawlik
Spencer Pawlik - avatar
3 Answers
31st Mar 2022, 4:32 PM
CalviŐ˛
CalviŐ˛ - avatar
+ 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"; }
31st Mar 2022, 5:56 PM
SoloProg
SoloProg - avatar
0
If you don't understand then ask here
31st Mar 2022, 3:46 PM
Spencer Pawlik
Spencer Pawlik - avatar