Search code examples
selectfocuslivejquery

Jquery live with select method problem in internet explorer


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 "-//W3C//DTD HTML 4.01 Transitional//EN" "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?


Solution

  • This is strange, it also works if you don't use the live event: http://jsfiddle.net/JKVXU/1/