My "Escape" event listener doesn't work, but if I type "Enter" instead of "Escape" it works with "Enter".
This is my code:
addEventListener("keypress", function (event) { if (event.key === "Escape") { spanClick(); } });
The problem is that the keypress event does not detect the "Escape" key. keypress events are generally only used for character keys and not special keys. Please use the keydown or keyup event instead.
keypress
keydown
keyup
The problem is that the
keypress
event does not detect the "Escape" key.keypress
events are generally only used for character keys and not special keys. Please use thekeydown
orkeyup
event instead.