Detect check boxes state in multi select dropdown

Detect check boxes state in multi select dropdown

I have a 'select' (dropdown) control with multiselect='multiselect' which shows checkboxes next to each item in the dropdown (code below). As you may notice, the first item is 'Select all', used to check/uncheck all other checkboxes. 

  1. <select id="test" multiple="multiple">
  2.     <option value="-1">Select all</option>
  3.     <option value="1">BMW</option>
  4.     <option value="2">Lexus</option>

I am trying to detect the checked event but it doesn't work, not sure what i am missing. Please suggest

  1. $("#test").change(function(){
  2.         if ($("#test select option:first-child").checked == true) {
  3.             alert("first child checked");
  4.         }
  5.         else{
  6.             alert("first child unchecked");
  7.         }

  8.     });