title: How to get alert of class name from selected option in select tag using jquery?
body: <p>I have a <code>&lt;select&gt;</code> tag with all options that are coming from the database. What I want to happen is when I select on a particular option, I want to get class name, but I am getting <code>Undefined</code> when I do it this way. Why is this happening?</p>
  
  <p><strong>HTML</strong>:</p>
  
  <pre><code>&lt;select id="mySelect"  class="form-control get-this"&gt;
      &lt;?php
               foreach ($res as $r) {
               ?&gt;
  
        &lt;option class="&lt;?= $r-&gt;item_name ?&gt;" &gt;&lt;?= $r-&gt;item_name ?&gt;&lt;/option&gt;
  
  
                &lt;?php }
              ?&gt;
  
         &lt;/select&gt;
  </code></pre>
  
  <p><strong>JavaScript</strong>:</p>
  
  <pre><code>&lt;script&gt;
         $('.get-this').on('change', function() { 
      var optionSelected = $("option:selected", this);
      var valueSelected = $('option:selected').attr('class'); 
  
  alert($(this).find('option:selected').attr("class"));
  
  }); 
  &lt;/script&gt;
  </code></pre>