javascript - Select all the text in an input, focusin -
i want have text selected when give focus element.
i used
$('.class-focusin').focusin(function(e) { $(this).select(); });
but it's not perfect behavior want. when click between 2 characters, input value not seleted, there cursor in middle. want behavior of url bar in chrome browser: click , cursor replaced value selection
feel free test problem in fiddle: http://jsfiddle.net/xs6s2/8/
i want text able receive cursor once selected. answer selected, below wanted, thanks
you have variable see if text has been selected or not:
http://jsfiddle.net/jonigiuro/xs6s2/21/
var has_focus = false; $('.class-focusin').click(function(e) { if(!has_focus) { $(this).select(); has_focus = true; } }); $('.class-focusin').blur(function(e) { has_focus = false; });
Comments
Post a Comment