title: How to hide options in a dropdown using select2 plugin?
body: <p>We are populating the options in a dropdown through list.The values are added in a list in Action class.
  When option is equal to a particular value , we want to hide it.</p>
  <p>Following is the code:</p>
  <pre><code>if (stuval.substring(0, 7) == &quot;&lt;option&quot;) {  
     $('#stuclass option:not(:first)').remove(); 
     $('#stuclass').find('option').end().append($(stuval));
  }                         
  </code></pre>
  <p>How to hide the option when value is 'Not apply'?</p>
  <p>We are using select2 plugin.Tried with following code in CSS.</p>
  <pre><code>.select2-results [data-select2-id*=&quot;not apply&quot;]{
    display : none;
   }
  </code></pre>
  <p>Problem with this code is it is removing 'not apply' option from all the dropdowns in the page.Requirement is how to apply for that dropdown(using id).Option should be hidden but not remoed or disabled.Kindly help</p>
  <p>HTML Code :</p>
  <pre><code>&lt;tr&gt;
                                  &lt;td&gt;&lt;b&gt;&lt;bean:message
                                              key=&quot;label.stuclass&quot; /&gt;:&lt;/b&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;html:select property=&quot;stuclass&quot; style=&quot;text-transform: uppercase;background-color: #A5A5A5;&quot;
                                          styleId=&quot;stuclass&quot;&gt;
                                  &lt;html:option value=&quot;&quot;&gt;&lt;bean:message key=&quot;label.stuclass.select&quot; /&gt;&lt;/html:option&gt;
                                  &lt;html:optionsCollection name=&quot;studentForm&quot; property=&quot;stuList&quot;  label=&quot;label&quot; value=&quot;value&quot; /&gt;
                                  &lt;/html:select&gt;&lt;/td&gt;
                              &lt;/tr&gt;
                          
                          While Jquery loading :
                          
                          $(&quot;#stuclass&quot;).select2({ width: '150px'});
  </code></pre>
  <p>Other Dropdown which has 'not apply' as one of its options:(values are loaded into this dropdown in backend through action class)</p>
  <pre><code>                        $(&quot;#stuStatusSearch&quot;).select2({ width: '150px'});
                          
                          
  
  &lt;html:select property=&quot;stuStatusSearch&quot; styleId=&quot;stuStatusSearch&quot;&gt;
                                  &lt;html:option value=&quot;&quot;&gt;&lt;bean:message key=&quot;label.stuStatusSearch.select&quot; /&gt;
                                  &lt;/html:option&gt;&lt;html:optionsCollection name=&quot;studentForm&quot; property=&quot;stuStatusList&quot; label=&quot;label&quot; value=&quot;value&quot; /&gt;
                              &lt;/html:select&gt;
  </code></pre>