If you're not familiar or comfortable with is()
, you could just check the value of prop("selected")
.
$('#mySelectBox option').each(function() {
if ($(this).prop("selected") == true) {
// do something
} else {
// do something
}
});?
Edit:
As @gdoron pointed out in the comments, the faster and most appropriate way to access the selected property of an option is via the DOM selector. Here is the fiddle update displaying this action.
if (this.selected == true) {
appears to work just as well! Thanks gdoron.