title: Getting data from select within each and selected option
body: <p>I am trying to get the data of the selected option based on if it has the attribute select. The problem is that when I use the prev function my code always returns the first option which is Position X(1, 2, ect). How can I get the data name of the selected option within my each loop for for example position 2 has Blue selected so I should be able to retrieve 0:finopt:1 or 0:finopt:5 from the position 6 which has the option Red selected from the data name of the option that has the selected attribute.</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(){
    $('.cart-product-options .cart option').each(function(sk,sv){
        if($(this).attr('selected')){
          console.log($(this).prev().prev().data('name'));
          console.log(sv);
        }
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="cart-product"&gt;
  &lt;tbody&gt;
  &lt;div class="cart-product-options"&gt;
  &lt;tr&gt;&lt;td class="opt_cart"&gt;
  &lt;select class="cart" name="0:finopt:0" size="1"&gt;
  &lt;option value="Position 1"&gt;Position 1&lt;/option&gt;
  &lt;option value="Red"&gt;Red&lt;/option&gt;
  &lt;option value="Blue"&gt;Blue&lt;/option&gt;
  &lt;option value="Amber"&gt;Amber&lt;/option&gt; 
  &lt;option value="Red/Blue"&gt;Red/Blue&lt;/option&gt;
  &lt;option value="Red/Amber"&gt;Red/Amber&lt;/option&gt;
  &lt;option value="Red/White"&gt;Red/White&lt;/option&gt;
  &lt;option value="Blue/Amber"&gt;Blue/Amber&lt;/option&gt;
  &lt;option value="Blue/White"&gt;Blue/White&lt;/option&gt;
  &lt;option value="Amber/White"&gt;Amber/White&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;&lt;td class="opt_cart"&gt;
  &lt;select class="cart" name="0:finopt:1" size="1"&gt;
  &lt;option value="Position 2"&gt;Position 2&lt;/option&gt;
  &lt;option value="Red"&gt;Red&lt;/option&gt;
  &lt;option value="Blue" selected&gt;Blue&lt;/option&gt;
  &lt;option value="Amber"&gt;Amber&lt;/option&gt;
  &lt;option value="White"&gt;White&lt;/option&gt;
  &lt;option value="Red/Blue"&gt;Red/Blue&lt;/option&gt;
  &lt;option value="Red/Amber"&gt;Red/Amber&lt;/option&gt;
  &lt;option value="Red/White"&gt;Red/White&lt;/option&gt;
  &lt;option value="Blue/Amber"&gt;Blue/Amber&lt;/option&gt;
  &lt;option value="Blue/White"&gt;Blue/White&lt;/option&gt;
  &lt;option value="Amber/White"&gt;Amber/White&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;&lt;td class="opt_cart"&gt;
  &lt;select class="cart" name="0:finopt:2" size="1"&gt;
  &lt;option value="Position 3"&gt;Position 3&lt;/option&gt;
  &lt;option value="Red"&gt;Red&lt;/option&gt;
  &lt;option value="Blue"&gt;Blue&lt;/option&gt;
  &lt;option value="Amber"&gt;Amber&lt;/option&gt;
  &lt;option value="White"&gt;White&lt;/option&gt;
  &lt;option value="Red/Blue"&gt;Red/Blue&lt;/option&gt;
  &lt;option value="Red/Amber"&gt;Red/Amber&lt;/option&gt;
  &lt;option value="Red/White"&gt;Red/White&lt;/option&gt;
  &lt;option value="Blue/Amber"&gt;Blue/Amber&lt;/option&gt;
  &lt;option value="Blue/White"&gt;Blue/White&lt;/option&gt;
  &lt;option value="Amber/White"&gt;Amber/White&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;&lt;td class="opt_cart"&gt;
  &lt;select class="cart" name="0:finopt:3" size="1"&gt;
  &lt;option value="Position 4"&gt;Position 4&lt;/option&gt;
  &lt;option value="Red"&gt;Red&lt;/option&gt;
  &lt;option value="Blue"&gt;Blue&lt;/option&gt;
  &lt;option value="Amber"&gt;Amber&lt;/option&gt;
  &lt;option value="White"&gt;White&lt;/option&gt;
  &lt;option value="Red/Blue"&gt;Red/Blue&lt;/option&gt;
  &lt;option value="Red/Amber"&gt;Red/Amber&lt;/option&gt;
  &lt;option value="Red/White"&gt;Red/White&lt;/option&gt;
  &lt;option value="Blue/Amber"&gt;Blue/Amber&lt;/option&gt;
  &lt;option value="Blue/White"&gt;Blue/White&lt;/option&gt;
  &lt;option value="Amber/White"&gt;Amber/White&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;&lt;td class="opt_cart"&gt;
  &lt;select class="cart" name="0:finopt:4" size="1"&gt;
  &lt;option value="Position 5"&gt;Position 5&lt;/option&gt;
  &lt;option value="Red"&gt;Red&lt;/option&gt;
  &lt;option value="Blue"&gt;Blue&lt;/option&gt;
  &lt;option value="Amber"&gt;Amber&lt;/option&gt;
  &lt;option value="White"&gt;White&lt;/option&gt;
  &lt;option value="Red/Blue"&gt;Red/Blue&lt;/option&gt;
  &lt;option value="Red/Amber"&gt;Red/Amber&lt;/option&gt;
  &lt;option value="Red/White"&gt;Red/White&lt;/option&gt;
  &lt;option value="Blue/Amber"&gt;Blue/Amber&lt;/option&gt;
  &lt;option value="Blue/White"&gt;Blue/White&lt;/option&gt;
  &lt;option value="Amber/White"&gt;Amber/White&lt;/option&gt;
  &lt;option value="Takedowns"&gt;Takedowns&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;&lt;td class="opt_cart"&gt;
  &lt;select class="cart" name="0:finopt:5" size="1"&gt;
  &lt;option value="Position 6"&gt;Position 6&lt;/option&gt;
  &lt;option value="Red" selected&gt;Red&lt;/option&gt;
  &lt;option value="Blue"&gt;Blue&lt;/option&gt;
  &lt;option value="Amber"&gt;Amber&lt;/option&gt;
  &lt;option value="White"&gt;White&lt;/option&gt;
  &lt;option value="Red/Blue"&gt;Red/Blue&lt;/option&gt;
  &lt;option value="Red/Amber"&gt;Red/Amber&lt;/option&gt;
  &lt;option value="Red/White"&gt;Red/White&lt;/option&gt;
  &lt;option value="Blue/Amber"&gt;Blue/Amber&lt;/option&gt;
  &lt;option value="Blue/White"&gt;Blue/White&lt;/option&gt;
  &lt;option value="Amber/White"&gt;Amber/White&lt;/option&gt;
  &lt;option value="Takedowns"&gt;Takedowns&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>