How to get the first form element (input element) that occurs on a page and set focus to it?
I would like to change the practice where I have to set focus manually in every single page to a certain element like this
$("#Clients").focus()
I want something universal, something that will figure out the first input automatically and put that code into a master page.
You can use the
:inputand:firstselectors with.focus(), like this:Or since you said master page, you may have a certain content area or something, so just prefix that on the selector, for example:
The
:inputselectors selects all input, textarea, select and button elements, so it’ll grab the first of any kind of<form>input.