lundi 13 novembre 2017

Checking if checkboxes are checked ornot, returns addEventListener is not a function

Hi I got the following code snippet where im trying to print a console.log dependent on if a checkbox has been checked or not.

var checkbox = document.querySelectorAll('.customer-club-widget__gender__categories .form__input-checkbox');
checkbox.addEventListener("change", function() {

var isChecked = checkbox.checked;
if(isChecked){ //checked
    console.log('checked');
}else{ //unchecked
    console.log('unchecked');
}

I keep getting the following error: Uncaught TypeError: checkbox.addEventListener is not a function and a cant figure out why this is happening.




Aucun commentaire:

Enregistrer un commentaire