jquery, set focus on the first enabled input or select or textarea on the page

Josh picture Josh · Dec 1, 2010 · Viewed 35.7k times · Source

It's fairly straightforward. I want to set focus to the first enabled and not hidden control on the page.

For a textbox, I have

$("input[type='text']:visible:enabled:first").focus();

But I want to get "all" form input controls: textbox, checkbox, textarea, dropdown, radio in my selector to grab the first enabled and not hidden control. Any suggestions?

Answer

Jordan Ryan Moore picture Jordan Ryan Moore · Dec 1, 2010
$(':input:enabled:visible:first').focus();