JQuery determine if one or more select has 3 options
Question
I have a page that contains 20 select's with a class name of '.ct'. I need a selector that determines if a select exists that contains 3 or more options.
Thanks, Chris
Solution
You can use the nth-child selector to check for a 3rd <option>
, like this:
if ($('select.ct option:nth-child(3)').length)
; // Do stuff
OTHER TIPS
var elem=$('select.ct');
var exist=false;
$.each(elem,function(index,value){
if(value.length>2)
{
exist=true;
return
}
})
if(exist)
alert('select option with option greater than 3 exist')
else
alert('no select option exist greater than 3')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow