Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.5.0.min.js"> </script> </head> <body> <h1>Check if an Enter Key is Pressed with jQuery</h1> <label>TextBox : </label> <input id="textbox" type="text" size="40" /> <script> $(document).on('keypress', function(event) { let keycode = (event.keyCode ? event.keyCode : event.which); if(keycode == '13') { alert('You pressed a "enter" key in somewhere'); } }); </script> </body> </html>