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.
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.
var selects = $('select').filter(function() {
return $(this).find('option').length === 2
});
or:
var selects = $('select').filter(function() {
return $('option', this).length === 2;
});
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.