This simple selector finds the first empty text input field in my form but skips over password type inputs:
$('input:text[value=""]:first').focus();
Is there a neat way to say :text or :password in the above statement?
This simple selector finds the first empty text input field in my form but skips over password type inputs:
$('input:text[value=""]:first').focus();
Is there a neat way to say :text or :password in the above statement?
$('input:text[value=""]').add('input:password[value=""]').first().focus();
I don't think there is a better way. That's what I thought before taking a look at @Hari Das answer which has an issue but brings alternative solution to my mind:
$('input:text[value=""],input:password[value=""]').first().focus()
Choose the one which is more readable to you.
Here a little custom expression :
$.expr[':'].is = function(a,b,c){
return $(a).is(c[3])
}
That allow you to use is
in a selector. You can achieve what you want with that :
$('input[value=""]:is([type=text],[type=password]):first')
By using comma you can insert multiple selector. It works like an OR operator.
$('input:text[value=""]:first,input:password[value=""]:first')
The visible is there to skip any hidden fields, such as select2 autogenerated inputs.
$('input:text[value=""]:visible:first',input:password[value=""]:first)