jquery - Check whether an item from a dropdown list is selected -


i have multi-select html dropdown list. want check on button click whether there item selected or not. if there no element selected, alert "item not selected" else selected items alert "selected".

if ($("#ddl1 >option").length >= 1) {      if ($("#ddl1 >option:selected").val() == 'undefined') {         alert("not selected");      } else {         alert("deleted");      }  } else     alert("list empty"); 

you can use length <= 0 here

if ($("#ddl1 > option").length >= 1) {     if ($("#ddl1 > option:selected").length <= 0) {         alert("not selected");     } else {         alert("deleted");     } } else alert("list empty"); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -