How to undo a focus event from an element

A difficult problem.

The script does something in mousedown, and then executes "keypress", "focusout", "keyup" anyway.

The question is how can I kill the two remaining events when one of them is completed.

I tried $(document).off() , $(this).off('focusout') and nothing works.

Any clues?

 .on('mousedown', '.task-content', function() { // Make DIV Editable }) .on('keypress', '.task-content', function (e) { if (e.which == 13 && !e.shiftKey) { // Update DIV content to DB } }) .on('focusout', '.task-content', function() { // Update DIV content to DB }) .on('keyup', '.task-content', function (e) { if (e.which == 27) { // Return DIV to previous state } }) 
+4
source share
1 answer

Your code is working fine, maybe you can specify the wrong selector .

 $('.task-content').on('keypress', function (e) { if (e.which == 13 && !e.shiftKey) { // Update DIV content to DB alert("key press"); $(this).off('focusout'); } }) $('.task-content').on('focusout', function () { // Update DIV content to DB alert("focus out "); }) 

Check the JSFiddle .

+1
source

Source: https://habr.com/ru/post/1487304/


All Articles