...
$(document).ready(function(){
$('form').submit(function(){
$('input#second').focus();
return false;
});
$('#first').blur(function(){
alert('blur');
});
});
...
<form>
<input id=first><br>
<input id=second><br>
<input type=submit>
</form>
...
- Load the page
- Click on first input to give it focus
- Hit Enter to submit the form
Then the following happens:
- $(‘form’).submit() is called and
- It sets focus to the #second input and exits
- #first looses focus, #second gets it, but…
- $(‘#first’).blur() is not called
Here is a live demo.
What am I missing?
Thanks
According to this comment over at JQuert bugtracker, the work around the problem is to
use
$('input#second')[0].focus();instead of
$('input#second').focus();Whether it is a bug is still to be decided by jq people in charge, but I would guess that it is because
Thanks, everyone. Night.