Ticket #8679 (closed bug: patchwelcome)
Jquery live with select method problem in internet explorer
| Reported by: | anonymous | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | selector | Version: | 1.5.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I want to use jquery live() to automatically select the text in a text box but it doesn't seem to work in internet explorer 8. Here's the code:
<!DOCTYPE html PUBLIC "-W3CDTD HTML 4.01 TransitionalEN" " http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript" src=" http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script> <script type="text/javascript"> $(function(){
$('input.textInput') .live('focus',
function(e){
$(this).select(); alert(1) if i uncomment this it works
});
}); </script>
</head> <body> <input type="text" class="textInput" value="0,00" /> </body> </html>
If, however, i uncomment the "alert(1)" statement it does work. Any ideas what the problem is here?
Change History
comment:2 Changed 2 years ago by addyosmani
- Priority changed from undecided to low
- Resolution set to patchwelcome
- Status changed from new to closed
- Component changed from unfiled to selector
Thanks for submitting a ticket to the jQuery Bug Tracker.As per timmywil's suggested workaround, you can easily use setTimeout to avoid the issue you're experiencing with IE8. Unless we find that a significant number of other users are also running into the same problem attempting such behavior using live with IE, we'll be closing this ticket as patch-welcome for now.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

You can do this instead: http://jsfiddle.net/timmywil/m9Pyu/1/ The setTimeout with a time of 0 places the .select at the bottom of the stack, allowing you to select after IE runs it's code to focus on the input.