views:

180

answers:

1

Hi,

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

+1  A: 

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
Greg
Thanks. The code is good but it didn't behave the way I needed it to. I'm going to repost in 5 minutes with code sample.
Or you can edit your question... depends how different it is.
Greg
Can you modify this selector to return only selects with exactly 2 options?
Yeah, the easiest way to do that would be `if($('select.ct > option').length == 2) { /* do stuff */ }`
KyleFarris