title: How to dynamically filter a select2 listing based on option class
body: <p>I have a dropdown select of optional 'opportunities' (<code>id="opportunities"</code> in the example below) which I enhance using the <a href="https://select2.github.io/" rel="nofollow noreferrer">select2 jquery plugin</a>, and wish to dynamically filter this list in order to reduce the possible options presented to a user using a 2nd select dropdown (<code>id="group-select"</code> in the example below),</p>
  
  <pre><code>&lt;label&gt;
    Select an opportunity&lt;br&gt;
    &lt;select id="opportunities" style="width:300px;" multiple="multiple" name="selected-opps" value=""&gt;
      &lt;optgroup label="Class A"&gt;
        &lt;option class="group-1" value="1a"&gt;Opportunity 1a&lt;/option&gt;
        &lt;option class="group-2" value="2a"&gt;Opportunity 2a&lt;/option&gt;
      &lt;/optgroup&gt;
      &lt;optgroup label="Class B"&gt;
        &lt;option class="group-1" value="1b"&gt;Opportunity 1b&lt;/option&gt;
        &lt;option class="group-2" value="2b"&gt;Opportunity 2b&lt;/option&gt;
      &lt;/optgroup&gt;
      &lt;optgroup label="Class C"&gt;
        &lt;option class="group-1" value="1c"&gt;Opportunity 1c&lt;/option&gt;
        &lt;option class="group-2" value="2c"&gt;Opportunity 2c&lt;/option&gt;
      &lt;/optgroup&gt;
    &lt;/select&gt;
  &lt;/label&gt;
  &lt;select id="group-select"&gt;
    &lt;option value=""&gt;Select a group&lt;/option&gt;
    &lt;option value="group-1"&gt;group 1&lt;/option&gt;
    &lt;option value="group-2"&gt;group 2&lt;/option&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;div id="select-opportunity"&gt;&lt;/div&gt;
  &lt;script type="text/javascript"&gt;
  (function( $ ) {
    'use strict';
  
     var opportunities = $('select#opportunities').select2({
      dropdownParent: $('#select-opportunity')
    });
  })( jQuery );
  &lt;/script&gt;
  </code></pre>
  
  <p>I wish to be able to make a selection in the 2nd select, say 'group 1' and would like the select2 list to contain only 'group-1' items as per the option in the first select dropdown that have the <code>grouo-1</code> class attribute.</p>