Naruto
Naruto

Reputation: 9634

Disable a particular keypress event in content editable div

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

Answers (2)

Naruto
Naruto

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

Soundar
Soundar

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

Related Questions