Kevin Watson Kevin Watson - 1 month ago 5x
Javascript Question

Multiple overriding 'keyup' events

In my application, I am listening to the keyups on a text input like this:


This works fine, however I also want to listen for the user pressing the UP or DOWN key anywhere in the rest of the document - so I tried adding the following (hoping jquery would use the input one inside the text box and the global one for anything else):

$(document).keyup(function(e) {

It has not done this, and chooses the global keyup for everything now. Is there any way I can get Jquery to do what I need here? I feel like it should be choosing the 'most specific' key up in each case, but it seems not...


you can use this way for listening to the user when pressing the UP key anywhere from entire document elements with exception for input[type='text']

        $(document).keyup(function(e) {
              return; <!-- you can handle keyup of input type text in this block -->
           else {
                <!-- handle your keyup of ducument code here -->