var inputHasFocus = false; jQuery("input").each( function() { if (!inputHasFocus && (this.type == 'text' || this.type == 'textarea' || this == 'password')) { jQuery(this).focus(); inputHasFocus = true; } });