When I click a button I want the textarea
in this li
element to focus.
Based on your comment in reply to Jacob, perhaps you want:
$('.user-status-buttons').click(function(){
var id = $(this).attr('id');
$("#commentbox-"+id).slideToggle("fast", function(){
$("#commentbox-"+id+" #StatusMessageReplyMessage").focus();
});
return false;
});
This should give the #StatusMessageReplyMessage
element focus after the slide effect has finished.
The easiest solution is to use jQuery focus
$('#StatusMessageReplyMessage').focus();
NOTE: if you are testing this in the console, Chrome will send the focus back to the console! This can lead you to believe it had not worked when in fact it works perfectly. Just be aware of other focus grabbing scripts/behavior in your environment and it will all be fine :)
I use timer to focus text areas :
setTimeout(function() {
$el.find('textarea').focus();
}, 0);