MCPcopy Create free account
hub / github.com/SuperSimpleDev/javascript-course / toggleButton

Function toggleButton

1-exercise-solutions/lesson-10/10g.js:2–14  ·  view source on GitHub ↗
(selector)

Source from the content-addressed store, hash-verified

1// The word "toggle" means turn on/off.
2function toggleButton(selector) {
3 const button = document.querySelector(selector);
4 if (!button.classList.contains('is-toggled')) {
5
6 // Before turning this button ON, check if there's
7 // already a button that's turned ON and turn it OFF.
8 turnOffPreviousButton();
9
10 button.classList.add('is-toggled');
11 } else {
12 button.classList.remove('is-toggled');
13 }
14}
15
16function turnOffPreviousButton() {
17 const previousButton = document.querySelector('.is-toggled');

Callers

nothing calls this directly

Calls 2

turnOffPreviousButtonFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected