Which keycode for escape key with jQuery

0 votes

I have two functions. When enter is pressed the functions runs correctly but when escape is pressed it doesn't. What's the correct number for the escape key?

$(document).keypress(function(e) { 
    if (e.which == 13) $('.save').click();   // enter (works as expected)
    if (e.which == 27) $('.cancel').click(); // esc   (does not work)
});

May 31, 2022 in JQuery by Edureka
• 13,690 points
3,251 views

1 answer to this question.

0 votes

27 is the code for the escape key. :) $(document). keypress(function(e) { y=e.

answered Jun 1, 2022 by Edureka
• 13,690 points

Related Questions In JQuery

0 votes
1 answer

How to convert form data to JavaScript object with jQuery?

Hello @kartik, You can use: function form_to_json (selector) { ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
3,147 views
0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello, Here is the syntax using jQuery $.get $.get(url, data, ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
43,951 views
0 votes
1 answer

How to set cache false for getJSON in jQuery?

Hello @kartik, Your code just needs a trigger ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
1,015 views
0 votes
1 answer

How do I pre-populate a jQuery Datepicker textbox with today's date?

Hello @kartik, You must FIRST call datepicker() > then use ...READ MORE

answered May 29, 2020 in JQuery by Niroj
• 82,840 points
12,234 views
0 votes
1 answer

Using setTimeout to delay timing of jQuery actions

The JavaScript setTimeout () function  is used ...READ MORE

answered May 30, 2022 in Java by gaurav
• 23,260 points
8,037 views
0 votes
1 answer

Best cross-browser method to capture CTRL+S with JQuery?

$(window).keypress(function(event) { if ...READ MORE

answered May 30, 2022 in JQuery by gaurav
• 23,260 points
1,585 views
0 votes
1 answer

jQuery.inArray(), how to use it right?

The jQuery inArray() method is used to find ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,690 points
539 views
0 votes
1 answer

JQuery opposite of extend (reduce objects)

There is no such function, but you ...READ MORE

answered Jun 2, 2022 in JQuery by Edureka
• 13,690 points
638 views
0 votes
1 answer

Get class list for element with jQuery

Use the jQuery attr() Method You can simply use the attr() method ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,690 points
6,237 views
0 votes
1 answer

Telerik UI controls vs client-side UI with jQuery

I've used Telerik and JQuery for years. ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,690 points
638 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP