Here's a tricky one to start the morning.
I have a series of icons. When you click an icon it loads a form. Some of the forms have input[text] others have textareas.
What I'm trying to come up with is jQuery that once I load the form I can run that will... Focus in on the first input or textarea whatever it may be, dynamically so I don't need if blocks.
Ideas?
The
:input
selector grabs all input, textarea, select and button elements.It's working for me in the load event.
EDIT
This is actually not that great of a solution. Patricia's and Onkelborg's solutions below are much more elegant.
Use instead:
or:
Also bear in mind when using
.focus()
Here is my solution. The code should be easy enough to follow but here is the idea:
The code:
Then simply call focusFirst with your parent element or selector.
Selector:
Element:
some of your code would be nice.. but this should be easy.
assuming your loading your for into a div that you know the id of....
all you have to do is something like
after you've loaded your form