detect when a key is pressed javascript code example
Example 1: how to check if enter is pressed javascript
$('#usersearch').keydown(function(e){
if(e.keyCode === 13){
alert("Enter was pressed ");
}
});
Example 2: js when key is pressed
document.addEventListener("keypress", function(event) {
// do stuff
});
Example 3: how to detect a keypress in javascript
window.addEventListener("keydown", (event) => {
console.log(event.key);
});