How do I know that the keyboard enter is pressed in jQuery?

Asked 2 years ago, Updated 2 years ago, 39 views

How do I know that the keyboard enter is pressed in jQuery? Is it possible? Or should I install a plug-in? I know I have to use the keypress() function, but I don't know how to use it.

javascript jquery

2022-09-22 11:15

1 Answers

All browsers treat Enter as 13.

$(document).keypress(function(e) {
    if(e.which == 13) {
        alert('You pressed enter!');
    }
});

You can do it like this.


2022-09-22 11:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.