I’m using jquery.hotkeys.js and mapping my keybinding in the following fashion:
$(document).bind('keydown', 'i', function() {
$("input#foo").focus()
});
Yet, after calling focus (in attempts to try and move the cursor to the end of the input field when hitting key i being focused on the document) it simply replaces the content of the input field with i. It’s possible to prevent the total replacement, however, the i still gets appended even after doing so. Example:
$(document).bind('keydown', 'i', function() {
var val = $("input#foo").val()
$("input#foo").focus()
$("input#foo").val(val.substring(0,val.length-1)
});
In this case, an input of television would turn into televisioi. Anyone of know any workarounds possible? Thanks!!
You can prevent the default functionality by passing the event:
I imagine you’ll want to prevent the keyup functionality too: