Skip to content
Advertisement

set back counter to 0 if nothing is checked Javascript

I have multiple dropdowns that contain checkboxes and my goal is “on click” to check how many boxes are checked and if it’s more than 1 to hide a logo.

I have 2 Problems.

Problem 1:

The counter never sets to 0 if no check box is checked.

Problem 2:

Every time I click it runs through the function multiple times and I end up getting multiple console.logs which is bad and confusing.

JavaScript
JavaScript

Any solution to the mentioned problems that I have is appreciated.

Advertisement

Answer

We can use filter() on the nodelist to get only the <input>‘s that are checked.

Then we can simplify the condition to:

  • Hide logo the amount of checked <input>‘s is not 1:
JavaScript

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement