var el = document.getElementById("myInputID");
el.addEventListener("keydown", function(event) {
if (event.key === "Enter") {
// Enter key was hit
}
});
const elem = document.getElementById("input");
elem.addEventListener("keypress", (event)=> {
if (event.keyCode === 13) { // key code of the keybord key
event.preventDefault();
// your code to Run
}
});
document.getElementById("yourElementId").addEventListener("keypress", function (event) {
if (event.key === "Enter") {
// the code you want to run
}
})
$('.container').on('keydown', 'input', function(e) {
if (e.keyCode === 13) {
e.preventDefault();
e.stopImmediatePropagation();
//Do your stuff...
}
});
// Get the input field
var input = document.getElementById("myInput");
// Execute a function when the user presses a key on the keyboard
input.addEventListener("keypress", function(event) {
// If the user presses the "Enter" key on the keyboard
if (event.key === "Enter") {
// Cancel the default action, if needed
event.preventDefault();
// Trigger the button element with a click
document.getElementById("myBtn").click();
}
});