Possible Duplicate:
jQuery OR Selector?
I would like to for each select
in the matched set find the first option
that either has a class placeholder
or an empty value something along the lines of
$(selectorOrJquery).find('select').andSelf().filter('select')
.find('(option.placeholder OR option[value=""]):first)
That is unfortunately not a valid sizzle (or CSS3) syntax - anyone know if there is a valid way to do this with selectors?
Obviously I could write procedural code to find this for me, but I'm hoping for something a bit more slick
Edit: To clarify, I do not think a comma simply works. Imagine the following
<select>
<option class="placeholder" value="0">Select Something</option>
<option value="">Legitimate option that gets handled in JS</value>
</select>
In this case I want only the first selected, NOT both
I have also run into an issue like this in the past and settled for something like this.
$(selectorOrJquery).find('select').andSelf().filter('select')
.find('option.placeholder, option[value=""]').eq(0);
This will return the first option of a select that is either empty or has a class placeholder.
$("select option:first").filter(":empty,.placeholder")
Just use a comma, which is a valid CSS/jQuery Selector.
$(selectorOrJquery).find('select').andSelf().filter('select')
.find('(option.placeholder, option[value=""]):first)
the css OR is the comma, so the selector you want would be
'option.placeholder:first, option[value=""]:first'
精彩评论