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
}
});
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER){
// Do something
}
}
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...
}
});
// Bind Enter key to search bar
$("#MySearchBar").keypress(function (e) {
if (e.keyCode === 13) {
MyVoidFunction();
}
});