I'm after the following functionality:
Is this possible?
$('input[type="text"]').live('focus', function () {
this.select();
});
http://jsfiddle.net/HmQxZ/13/
Chrome and IE8 selects all the text for only a split second
$('input[type="text"]').live('click', function () {
this.select();
});
http://jsfiddle.net/HmQxZ/12/
Firefox and IE8 selects all text but upon subsequent clicking, the text remains selected.
*kind of works, after textbox has focus, clicking on it alternates between selecting all text and being able to click where the blinking caret goes. This is probably acceptable.
Just delay it by a millisecond with setTimeout
:
$('input[type="text"]').live('focus', function() {
var inp = this;
setTimeout(function() {
inp.select();
}, 1);
});
http://jsfiddle.net/HmQxZ/14/
What's happening is some other browser event is setting the selection after you've selected the text. So, by waiting a millisecond, you let all the browser events finish, and then select the text. Nothing will undo it now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With