jQuery: on focus, do customized focus on textarea
Posted
by
evilReiko
on Stack Overflow
See other posts from Stack Overflow
or by evilReiko
Published on 2011-01-09T08:25:27Z
Indexed on
2011/01/09
8:54 UTC
Read the original article
Hit count: 270
jQuery
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?
© Stack Overflow or respective owner