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
Post a Comment