tags:

views:

71

answers:

3

Hi, how can one select an input "or" a select element with jQuery? I have a form, and I want to get the first element of that form that is an input or a select. So, this $('#myForm').find('input:first') or $('#myForm').find('select:first'). Any idea? Thanks

+3  A: 

Have you tried something like this?

$('#myForm select, #myForm input').first()
Rob Davis
A: 

Try this:

$('#myForm').find('input:first, select:first').first()
joshperry
Thanks a lot! That solved my problem.
Ricardo
+1  A: 

This should do the trick...

$('#myForm :input').first()  

:input "Matches all input, textarea, select and button elements." from the jquery docs.
.first() "Reduce the set of matched elements to the first in the set." also from the jquery docs.

Dr. Frankenstein