views:

80

answers:

2

Hi,

I can't figure out how to do something in Jquery. Let's say I have a form with many select drop-downs and do this...

$('#a_form select').each(function(index) {

});

When inside this loop I want to loop over each of the options, but I can't figure out how to do this, is it something like this....?

    $('#a_form select').each(function(index) {

        $(this + 'option').each(function(index) {
           //do things
        });
});

I can't quite get it to work, and advice? Cheers.

+3  A: 

I believe you want to write $('option', this).
You can also write $(this).find('option').

SLaks
or $(this).children()
Zlatev
@Zlatev: In this particular case, that will also work, but in general, it's not the same.
SLaks
A: 

I would try

$('#a_form select option').each(function(index) {
  //do those things
});
James Westgate
I assume that he's doing other things in the outer `.each`.
SLaks
Yeah, I want to do things specific to each select or else I would have gone with that...
Smickie
you could do this after looping over the selects, rather than nesting the options loop. it would work if you are always doin the same thing to the options, and might be a big faster
Yisroel