Reputation: 9634
i have a content editable div, i want to disable the undo operation i.e control + z operation on the editable div, i tried like this
//key up handles all keypresse events. Backspace wont fire for simple keypress event in jquery
$("#Partner").keyup(function (e) {
if (e.keyCode == 90) {
e.preventDefault();
return;
}
still i am able to perfrom undo operation, any input on how to disable undo on editable div?
Upvotes: 0
Views: 2293
Reputation: 9634
Here is the solution
$("#Partner").keydown(function (e) {
if (e.keyCode == 90 && e.ctrlKey) {
e.preventDefault();
return;
}
});
//key up handles all keypresse events. Backspace wont fire for simple keypress event in jquery
$("#Partner").keyup(function (e) {
if (e.keyCode == 90 && e.ctrlKey) {
e.preventDefault();
return;
}
Upvotes: 1
Reputation: 2589
Try this...
$("#Partner").bind("keydown", function (e) {
if (e.keyCode == 90 && e.ctrlKey) {
e.preventDefault();
return;
}
}
Note: the key operations are performed in the keydown operation also. so try to prevent the keydown event to block the default behavior.
Upvotes: 0