Selecting text on focus using jQuery not working in Safari and Chrome
focus, google-chrome, jquery, safari, select
Solution
It's the onmouseup event that is causing the selection to get unselected, so you just need to add:
$("#souper_fancy").mouseup(function(e){
e.preventDefault();
});
Problem
I have the following jQuery code (similar to this question) that works in Firefox and IE, but fails (no errors, just doesn't work) in Chrome and Safari. Any ideas for a workaround? ``` $("#souper_fancy").focus(function() { $(this).select() }); ```
Related problems
- jquery input select all on focus
- Programmatically selecting text in an input field on iOS devices (mobile Safari)
- Looking for a better workaround to Chrome select on focus bug
- Select all contents of textbox when it receives focus (Vanilla JS or jQuery)
- selectionStart/selectionEnd on input type="number" no longer allowed in Chrome