Id like to select all text from input on focusing:
<input id="selectMe" value="123" />
<input type="button" id="focusHim" value="Im working fine" />
JS:
$('#selectMe').focus( function() {
$(this).select();
console.log('focus fired');
});
// little test if focus event works fine
$('#focusHim').click( function() {
$('#selectMe').focus();
});
This simplified code works fine, but sometimes there are some issues.
Here you have fiddle: http://jsfiddle.net/daxv2/
To see my problem, please click on input #selectMe
, then click somewhere else and on #selectMe
again. You will see, text is selected every even attempt. I don't know why.
P.S.
When you change focus
to click
it works perfect:
$('#selectMe').click( function() {
$(this).select();
console.log('focus fired');
});
So i suppose there is some problem with focus
event.