$('#mySelectBox option').each(function() {
if ($(this).isChecked())
alert('this option is selected');
else
alert('this is not');
});
Apparently, the isChecked
doesn't work. SO my question is what is the proper way to do this?
Thanks.
use
to test if its a particular option
myoption
:In my case I don't know why selected is always true. So the only way I was able to think up is:
UPDATE
A more direct jQuery method to the option selected would be:
Answering the question
.is(':selected')
is what you are looking for:The non jQuery (arguably best practice) way to do it would be:
Although, if you are just looking for the selected value try:
If you are looking for the selected value's text do:
Check out: http://api.jquery.com/selected-selector/
Next time look for duplicate SO questions:
Get current selected option or Set selected option or How to get $(this) selected option in jQuery? or option[selected=true] doesn't work