how to enable a disabled event handler with jquery

Rockstar5645
$("#messageArea").keydown(function(e) {                             
    if((e.which != 13) && (e.keyCode != 27)) {
        var $this = $(this);
        $this.off();
        socket.emit("imTyping");
        setTimeout(function() {
            $this.on();
        }, 2000);
    } 
});

I'm trying to create a chat app that lets one person know when the other person is typing. This event handler listens for any key press (except enter and esc) and emits the "imTyping" message to the server. After THIS event handler is called, I want to disable (so I don't send a million messages to the server) and then enable it again after 2 seconds. That isn't happening, once it disables it, it PERMANENTLY disables it.

Also I have other event handlers for the messageArea element, so I only want to turn of THIS handler, and not any of the others.

AmmarCSE

Extract into a named function and pass in the correct parameters when unbinding/rebinding

$("#messageArea").keydown(typingKeydown);

function typingKeydown(e) {                             
    if((e.which != 13) && (e.keyCode != 27)) {
        var $this = $(this);
        $this.off('keydown', typingKeydown);
        socket.emit("imTyping");
        setTimeout(function() {
            $this.on('keydown', typingKeydown);
        }, 2000);
    } 
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to enable a disabled event handler with jquery

From Dev

How to Enable Disabled different Input in Select Event using jQuery

From Dev

Enable disabled Radiobuttonlist with jQuery

From Dev

How to enable an event handler, after .one() function was called?

From Dev

How to work with Click Event Handler jQuery

From Dev

how to store and reuse a timeout in a jQuery event handler?

From Dev

How to work with Click Event Handler jQuery

From Dev

jQuery: How can i enable the disabled anchor tag

From Dev

How to re-enable jQuery tooltip after disabled = true?

From Dev

How to enable chosen selectbox which is already disabled on button click in jquery?

From Dev

how to re-enable JQuery .one click handler

From Dev

jQuery .on data or event handler?

From Dev

jQuery event handler organisation

From Dev

Event handler on jQuery object

From Dev

jQuery event handler organisation

From Dev

jQuery event handler logic

From Dev

Dynamic jQuery event handler

From Dev

jQuery 'this' scope in event handler

From Dev

Jquery Event Handler Functions

From Dev

Jquery Event Handler ".on()"

From Dev

How to enable a disabled checkbox dynamically?

From Dev

Disabled Cortana, how to enable it now?

From Dev

How to run click event handler in Internet Explorer 10 using jquery?

From Dev

How to Exclude Child Element from jQuery Event Handler?

From Dev

how can $(this) not be the element that triggered the event in a jquery click handler?

From Dev

How do I use $(this) in a jQuery hover event handler?

From Dev

How to get jQuery to trigger a native custom event handler

From Dev

How to use jQuery ajax requests to trigger a code behind event handler

From Dev

How do I bind this event handler in a jQuery plugin?

Related Related

  1. 1

    how to enable a disabled event handler with jquery

  2. 2

    How to Enable Disabled different Input in Select Event using jQuery

  3. 3

    Enable disabled Radiobuttonlist with jQuery

  4. 4

    How to enable an event handler, after .one() function was called?

  5. 5

    How to work with Click Event Handler jQuery

  6. 6

    how to store and reuse a timeout in a jQuery event handler?

  7. 7

    How to work with Click Event Handler jQuery

  8. 8

    jQuery: How can i enable the disabled anchor tag

  9. 9

    How to re-enable jQuery tooltip after disabled = true?

  10. 10

    How to enable chosen selectbox which is already disabled on button click in jquery?

  11. 11

    how to re-enable JQuery .one click handler

  12. 12

    jQuery .on data or event handler?

  13. 13

    jQuery event handler organisation

  14. 14

    Event handler on jQuery object

  15. 15

    jQuery event handler organisation

  16. 16

    jQuery event handler logic

  17. 17

    Dynamic jQuery event handler

  18. 18

    jQuery 'this' scope in event handler

  19. 19

    Jquery Event Handler Functions

  20. 20

    Jquery Event Handler ".on()"

  21. 21

    How to enable a disabled checkbox dynamically?

  22. 22

    Disabled Cortana, how to enable it now?

  23. 23

    How to run click event handler in Internet Explorer 10 using jquery?

  24. 24

    How to Exclude Child Element from jQuery Event Handler?

  25. 25

    how can $(this) not be the element that triggered the event in a jquery click handler?

  26. 26

    How do I use $(this) in a jQuery hover event handler?

  27. 27

    How to get jQuery to trigger a native custom event handler

  28. 28

    How to use jQuery ajax requests to trigger a code behind event handler

  29. 29

    How do I bind this event handler in a jQuery plugin?

HotTag

Archive