Reputation: 980
I am using jeresig's jQuery Hotkeys library to enable hotkeys that can select a text area on a webpage. However, when I use the hotkey, it inserts text into the text area instead of only selecting it, overwriting the previous content, which is not what I want. Is there a solution to this?
HTML:
<input id='test' type='text' value='content'> <span class='button'>Button</span>
JavaScript:
$(document).ready(function () {
// Clicking button selects associated text area
$('.button').click(function () {
$(this).siblings('input:text').focus();
});
// Hotkeys for text area
$(document).bind('keypress', 'a', function () {
$('#test').focus()
});
});
Upvotes: 0
Views: 370
Reputation: 1571
Don't use keypress
event, it can be executed many times. Use keyup
instead.
Upvotes: 2