title: @Html.DropDownListFor - How to set color for the selected item using a jQuery or JavaScript class selector?
body: <p>I have displayed multiple dropdownlists using <code>@Html.DropDownListFor</code> html helper in single view. There are three options in the dropdownlist select options which are Present, Absent and Leave, I want when option from a list is selected the color for option text Present become Green, the color for option text Absent become Red and the color for option text Leave become Purple</p>
  <p><strong>HTML Part:</strong></p>
  <pre><code>@Html.DropDownListFor(m =&gt; m.AttendanceTypes, ViewBag.SelecAttType as SelectList, &quot;Select&quot;, new { @class = &quot;dropdown text-center  fw-bold border-0 bg-transparent TypeColor&quot;, style = &quot;color: #22BAD9 !important; width:100px !important;&quot; })
  </code></pre>
  <p>in above code <code>@Html.DropDownListFor</code> have <code>id=&quot;AttendanceTypes&quot;</code> as well as <code>class=&quot;TypeColor&quot;</code></p>
  <p>as I have multiple dropdowns in single view for that purpose I do not want to use <code>id</code> but a class</p>
  <p><strong>Below is a jQuery part I tried.</strong></p>
  <pre><code>$(&quot;.TypeColor&quot;).change(function () {
      if ($(&quot;.TypeColor option:selected&quot;).text() == 'Present') {
          $(&quot;.TypeColor&quot;).css('color', 'green');
      }
      else if ($(&quot;.TypeColor option:selected&quot;).text() == 'Absent') {
          $(&quot;.TypeColor&quot;).css('color', 'Red');
      }
      else if ($(&quot;.TypeColor option:selected&quot;).text() == 'Leave') {
          $(&quot;.TypeColor&quot;).css('color', 'Purple');
      }
  });
  </code></pre>
  <p>if in the above code replace all <code>.TypeColor</code> with <code>#AttendanceTypes</code> it work great but just for first dropdown and not for all the dropdowns. That's why I want to use class instead of id in jQUery part so that I can get the same results for all the dropdowns. But using class <code>.TypeColor</code> in the above jQuery part of code it is not changing any colors.</p>