js event.key enter code example
Example 1: javascript enter event listener
document.querySelector('#txtSearch').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
}
});
Example 2: javascript key pressed enter
$('.container').on('keydown', 'input', function(e) {
if (e.keyCode === 13) {
e.preventDefault();
e.stopImmediatePropagation();
}
});
Example 3: input enter button js
var input = document.getElementById("myInput");
input.addEventListener("keyup", (event) => {
if (event.key === "Enter") {
event.preventDefault();
document.getElementById("myBtn").click();
}
})