I’m trying to loop through a select tag, with multiselect. I’m new to jQuery and I found this code, however I need to loop through all of the option tags, checking whether the option is selected or not, as I need to do something in both cases.
$('.multiselect').change(function () {
$('.multiselect option:selected').each(function () {
//do something
});
}).trigger('change');
I was trying to make it into something more like this:
$('.multiselect').change(function () {
$('.multiselect').each(function () {
$('option', this).each(function() {
if ('option':selected == true) {
//do something
}
else {
//do something else
}
});
});
}).trigger('change');
But this doesn’t work. Can someone suggest a good approach?
Should work, I think.