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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -