javascript event listener keypress code example
Example 1: js when key is pressed
document.addEventListener("keypress", function(event) {
});
Example 2: how do i listen to a keypress in javascript
let b = document.getElementById("body");
b.addEventListener("keydown", (evt) => {
console.log(evt.keyCode);
});
Example 3: adding event listener keypress event in javascript
let msg = document.getDocumentById('#message');
msg.addEventListener("keydown", (event) => {
});
msg.addEventListener("keypress", (event) => {
});
msg.addEventListener("keyup", (event) => {
});