The select()
method in jQuery simply triggers the select event on all matched objects. You need to do something fancier if you want to manipulate the selected range of text in a textbox. Modern browsers behave differently here.
The following code should work in Chrome, Firefox, IE, Safari, and Opera:
<input type="text" id="textBox" />
<script type="text/javascript">
$(document).ready(function(){
function textBox_click(ev) {
if (this.createTextRange) {
// This is for IE and Opera.
range = this.createTextRange();
range.moveEnd('character', this.value.length);
range.select();
} else if (this.setSelectionRange) {
// This is for Mozilla and WebKit.
this.setSelectionRange(0, this.value.length);
}
}
$('#textBox').click(textBox_click);
});
</script>