jQuery event.which detect enter key press

Description

jQuery event.which detect enter key press

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Check if Enter Key is Pressed with jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).on("keypress", function(e){
        if(e.which == 13){/*from   w  w w  .j  a v  a 2  s.  c  o  m*/
            $("body").append("<p>You've pressed the enter key!</p>");
        }
    });
</script>
</head>
<body>
    <p>Click on the viewport and press the Enter key on the keyboard. 
    </p>
</body>
</html>



PreviousNext

Related