Answers for "javascript event listener keypress"

14

js when key is pressed

document.addEventListener("keypress", function(event) {
	// do stuff
});
Posted by: Guest on March-08-2020
0

how do i listen to a keypress in javascript

let b = document.getElementById("body"); //making var for body
b.addEventListener("keydown", (evt) => {//when this happens
	console.log(evt.keyCode); //log keycode
});
Posted by: Guest on November-28-2020
0

adding event listener keypress event in javascript

let msg = document.getDocumentById('#message');

msg.addEventListener("keydown", (event) => {
    // handle keydown
});

msg.addEventListener("keypress", (event) => {
    // handle keypress
});

msg.addEventListener("keyup", (event) => {
    // handle keyup
});
Posted by: Guest on November-18-2020

Code answers related to "javascript event listener keypress"

Browse Popular Code Answers by Language