javascript - Prevent keypress to bubble to input in mousetrap -


i using mousetrap capturing key presses. 1 of shortcuts want define focus on input.

mousetrap.bind('i', function() { $('.input').focus() });

the focussing works fine, 'i' keypress gets bubbled input, , being focussed, input gets populated 'i'.

is there way prevent 'i' being written in input? appreciated.

thanks

right there in documentation:

as convenience can return false in callback:

mousetrap.bind(['ctrl+s', 'meta+s'], function(e) {     _savedraft();     return false; }); 

returning false here works same way jquery's return false. prevents default action , stops event bubbling up.

so:

mousetrap.bind('i', function() {     $('.input').focus();     return false; }); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -