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.
- <select id="test" multiple="multiple">
- <option value="-1">Select all</option>
- <option value="1">BMW</option>
- <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
- $("#test").change(function(){
- if ($("#test select option:first-child").checked == true) {
- alert("first child checked");
- }
- else{
- alert("first child unchecked");
- }
-
- });