jQuery <input> detect the enter key press in a text input field
<!DOCTYPE html> <html lang="en"> <head> <title>Detect If Enter Key is Pressed in a Text Input Field with jQuery</title> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script> $(document).on("keypress", "input", function(e){ if(e.which == 13){//from ww w . j a va 2 s . co m var inputVal = $(this).val(); document.getElementById("demo").innerHTML = "You've entered: " + inputVal; } }); </script> </head> <body> <p id="demo"></p> <input type="text"> </body> </html>