views:

464

answers:

3

I've got this little snippet of jQuery:

$('#showlink').click(function(){ 
 $('#linkwindow').show('fast');
 $('#linkwindow input').focus();
}

How do I call the focus only after the fade has ended? Sometimes it happens slightly before and I end up with a weird rendering bug.

+3  A: 

Try this, using the callback parameter.

$('#showlink').click(function(){  
  $('#linkwindow').show('fast', function() {
    $('#linkwindow input').focus();
  });
});
bendewey
+5  A: 

You may add a callback to the show method:

$('#showlink').click(function(){ 
    $('#linkwindow').show('fast', function() {
        $('#linkwindow input').focus();
    });
})
moff
A: 

Use the callback second parameter.

Something like:

$('#linkwindow').show('fast', function() { 
    $('#linkwindow input').focus(); 
});
Adrian Godong