javascriptjquerycss-selectorseachnested-loops

Jquery - $(this) in nested loops


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.


Solution

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