jQuery: on focus, do customized focus on textarea
- by evilReiko
My Code:
$('#myTextArea').one('focus', function() {
$('#myTextArea')[0].selectionStart = 2;
$('#myTextArea')[0].selectionEnd = 6;
$('#myTextArea')[0].focus();
});
The code works fine, on focus (only once), it selects from index 2 to 6.
The problem: since this function is called on focus, it does the custom focus, but then it calls focus AGAIN and I lose focus of the selected text. Any possible solution?