dimanche 1 mars 2020

addEventListener and if statement on button clicked

I am new to coding and here I am trying to use addEventListener and if statement to change the color of the box when button clicked, but I am not doing it the right way and not managing to find the proper way online. I hope someone can help. Thank you!

var box = document.getElementById("box");
var yes = document.getElementById("yes");
var no  = document.getElementById("no");
yes.addEventListener("click", function(){
    if (yes.clicked == true){
        box.style.backgroundColor = "red";        
    } if(no.clicked == true) {
        box.style.backgroundColor = "green";
    }
});

Aucun commentaire:

Enregistrer un commentaire