I create a game on Canvas / Javascript. There is a sound button when clicking should change the sound icon (on / off). onklik does not work
var vol = true; if (vol == true) { ctx.drawImage(volume, 900, 20, 35, 35); } if (vol == false) { ctx.drawImage(volume_muted, 900, 20, 35, 35); } volume.onclick = function () {vol=false;}; volume_muted.onclick = function () {vol=true;}; does not work through click
volume.addEventListener("click", vold); function vold() { vol = false; } but through keydaun works
document.addEventListener("keydown", vold); function vold(b) { if (b.keyCode) {vol = false;} }