XristosK
XristosK

Reputation: 264

Dropdown box: How to know if a value is selected or not

in the code below, I need to know what choice is being selected. What is the appropriate way? Thank you

$(window).ready(function() { 
    $("#Tmimata > option").each(function(index) {
         var mythis = $(this);
         if (mythis.selected) { 

         }
         else {

         }
    });
 });

Upvotes: 0

Views: 220

Answers (2)

Darren
Darren

Reputation: 13128

you'd use the :selected selector

if (mythis.is(':selected')) { 

}

Upvotes: 0

martynas
martynas

Reputation: 12290

To check if the element is selected, you should use .prop():

if (mythis.prop('selected')) {
    // do something
}

Upvotes: 1

Related Questions