I want to set focus to the first empty input or textarea element, in a Form
I know that the following jQuery code sets focus to the first input or textarea on a page but how do i limit it to a specific form?
$("textarea:empty,input:text[value='']").first().focus();
CodePudding user response:
You can just target your form first and then find() the first empty element inside the form:
$("#your-form").find("textarea:empty,input:text[value='']").first().focus();
this focuses the first empty field inside a form with id your-form
:
<form id="your-form">
...
</form>