Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to execute cntrl+z using jquery code seems to be fine but its not working.
can anyone help me with this please.
My code is as follows:

$(document).keydown(function(e){
if(e.keyCode==90 && e.ctrlKey)
{
alert('cnttrl z pressed');
}
});

tried putting 90 in single quotes '90' not working
tried (e.keyCode==90 && e.keyCode==17) not working
tried keyup instead of keydown not working

Thanks in advance
Posted
Comments
Nathan Minier 4-Nov-14 7:18am    
Works fine for me, cut and pasted, providing jQuery is loaded first.
ZurdoDev 4-Nov-14 7:40am    
Looks like it works. All you have to do is debug it to see what is happening.
yedhuvamshi 4-Nov-14 7:53am    
Hey! Thanks so much everyone for the replies !!! But the problem still remains unsolved.
By debugging i'm getting the e.keyCode value as 17 and the code inside if loop is not executing. It doesn't enter loop. Since the value appears 17 not 90 and hence the if condition is false.

1 solution

Hi,

Your code works fine for me too. This is the way I used your code:
JavaScript
$(document).ready(function () {
            $(document).keydown(function (e) {
                if (e.keyCode == 90 && e.ctrlKey) {
                    alert('Control + Z is pressed');
                }
            });
        });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900