title: Bootstrap multiselect dropdown deselect same value option from optgroup
body: <p>I used bootstrap multiselect js. When I deselect any optgroup or option then same value option will be deselected from the dropdown.
  I tried but it's not working properly.</p>
  
  <p><a href="http://jsfiddle.net/c3mpjzte/24/" rel="nofollow noreferrer">http://jsfiddle.net/c3mpjzte/24/</a></p>
  
  <p>My code:</p>
  
  <pre><code>$('#MessageToUser').multiselect({
    enableFiltering: true,
    filterBehavior: 'text',
    buttonWidth: '100%',
    enableClickableOptGroups: true,
    enableCollapsibleOptGroups: true,
    nonSelectedText: 'Select User',
    //includeSelectAllOption: true,
    maxHeight: 300,
    templates: {
      button: '&lt;span class="multiselect dropdown-toggle" data-toggle="dropdown"&gt;To User&lt;/span&gt;'
    },
    onChange: function(option, checked) {
      debugger
      if (checked == false) {
        var a = [];
  
        if (Array.isArray(option) == true) {
          $.each(option, function(i, value) {
            a.push(option[i].val());
          })
  
          $.each(option, function(index, value) {
            $('#MessageToUser option:selected').each(function(i, obj) {
              if ($(this).val() == option[index].val()) {
                $(this).prop("selected", false);
              }
            });
          });
  
          $('#MessageToUser').multiselect('deselect', a);
        } else {
          $('#MessageToUser option:selected').each(function(i, obj) {
            if ($(this).val() == option.val()) {
              $(this).prop("selected", false);
            }
          });
  
          $('#MessageToUser').multiselect('deselect', [option.val()]);
        }
  
        //$("#MessageToUser").multiselect("refresh");
      }
  
      $("#MessageToUser").next().find("button.multiselect span.multiselect-selected-text").text("Selected To Users");
    }
  });
  </code></pre>