title: Jquery find each dynamically generated select inside div and add class to select if option value is " "
body: <p>I have dynamically generated select fields inside a div called mydiv.
  The id and class names  also for each of my select fields are also dynamically generated.</p>
  
  <p>I am trying to add a class called red-border to each of my select elements inside mydiv based on the value.</p>
  
  <p>for example if Not mapped is selected by default its value is " " empty in my first select than class red-border gets added to my first select </p>
  
  <p>Here is my js please help </p>
  
  <pre><code>$('[class^="mydiv"]').find('option').each(function() {
      var myvalue= $(this).val();
      if (myvalue===" "){
          $(this).addClass("red-border");
      }else{
          $(this).addClass("green-border");
      }
  });
  
  &lt;div class="mydiv" id="mydiv"&gt;
      &lt;select id="dynamically_generated_select_169" class="someclass169"&gt;
          &lt;option value=" "&gt;Not mapped&lt;/option&gt;
          &lt;option value="1"&gt;Saab&lt;/option&gt;
          &lt;option value="2"&gt;VW&lt;/option&gt;
          &lt;option value="3" selected&gt;Audi&lt;/option&gt;
      &lt;/select&gt;
  
      &lt;!-- Another select Each select and its options are all dynamically generated --&gt;
  
      &lt;select id="dynamically_generated_select_170"class="someclass170"&gt;
          &lt;option value="1"&gt;Saab&lt;/option&gt;
          &lt;option value=" "&gt;Not mapped&lt;/option&gt;
          &lt;option value="2"&gt;VW&lt;/option&gt;
          &lt;option value="3" selected&gt;Audi&lt;/option&gt;
      &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>