I have a variable that hold different form-objects like this … $(formId)
Each form is different as in either has an hidden input field as first element or the first-child is a normal input (type="text" or something else)
how can I ALWAYS select the the first "normal" input field
$(formId).find("input:first-child:not[type='hidden']")
I thought it should be something like this. So if you wonder what I need this for - I want to set the focus to the first input field in the form, but if the first input is a hidden one I of course want to set it to the next "visible" input.
The :first-child
selector selects an element which is the first child, not the first item in a jQuery collection.
To select the first element of a collection, use jQuery's :first
selector.
Your implementation of :not
is also wrong.:not[type='hidden']
is equal to :not()[type='hidden']
is equal to [type='hidden']
- The opposite of what you want.
input:not([type=hidden]):first
input[type!=hidden]:first
$(formId).find ('input:visible:first').focus();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With