Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery Hotkeys - enabling a combination while INSIDE a input/textarea

I'm using the jQuery hotkeys plugin here: https://github.com/tzuryby/jquery.hotkeys

The plugin prevents hot keys from firing when you are inside an input field.

In my case, I want a hotkey to fire when inside an input box, not all but one in particular:

$(function() {
    $(document).bind('keydown', 'Shift+return',function (evt) {
        alert('got it')
    });
});

Any ideas on how jQuery Hotkeys can be patched to allow for shift+return to be fired when inside an input/textarea field? but not fired for all the other hotkey bindings?

Thanks

like image 543
TheExit Avatar asked Jul 17 '26 14:07

TheExit


1 Answers

According to the documentation, you can bind the event handler to any expression (not just document as in your example). You could explicitly bind the shift+return handler to whatever input elements you want by using a selector:

$("#test").bind("keydown", "shift+return", function(event) {
    alert('got it');
});

Where test is the id of the input you want to listen to for the event.

I have it working here: http://jsfiddle.net/andrewwhitaker/vKrM9/

like image 158
Andrew Whitaker Avatar answered Jul 19 '26 06:07

Andrew Whitaker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!