title: how to select remaining elements in multi select
body: <p>I have a multi select html field which includes categories and the elements relating to those categories</p>
  
  <p>I want a person to be able to select individual courses or if they select a category (value prefixed with cat_) then it should mark the following courses as selected until it finds the next category</p>
  
  <p>I have tried a few things but with no success</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
  
  
    $('#courses').change(function() {
  
      $(this).nextUntil('option[name^="cat_"]').each().prop("selected", "selected");
      $(this).nextUntil('option[name^="cat_"]').prop("selected", "selected");
      $(this).closest("option").nextAll().each(function() {
        $this.prop("selected", "selected");
      });
  
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;select class="form-control" name="courses[]" id="courses" multiple="true"&gt;
    &lt;option value="cat_1"&gt;data / &lt;/option&gt;
    &lt;option value="1"&gt;data / Guitar &lt;/option&gt;
    &lt;option value="2"&gt;data / keyboard &lt;/option&gt;
    &lt;option value="cat_2"&gt;mandatory / &lt;/option&gt;
    &lt;option value="cat_3"&gt;fb / &lt;/option&gt;
    &lt;option value="3"&gt;fb / Node js &lt;/option&gt;
    &lt;option value="4"&gt;fb / PHP programming &lt;/option&gt;
    &lt;option value="5"&gt;fb / C# &lt;/option&gt;
  
  &lt;/select&gt;</code></pre>
  </div>
  </div>
  </p>