tags:

views:

68

answers:

2

I need to find all select's with exactly 2 options. The code I'm using is:

$('select.ct option:nth-child(2)')

but it seems to get everything with more than 2 options.

+2  A: 
var selects = $('select').filter(function() {
    return $(this).find('option').length === 2
});

or:

var selects = $('select').filter(function() {
    return $('option', this).length === 2;
});
meder
+3  A: 

This will also work:

$('select:has(option:first-child + option:last-child)');

Basically it looks for a select element that contains an option element that is the first child and is adjacent to an option that is the last child.

Marve
nice, I didn't think of that.
meder