jquery insert option before option with greater class
<p>Hi i want create function which will after clicking button remove option from one list and insert in to another but <code>before</code> option with <code>class</code> with grater suffix than one that i selected. Class name is <code>opt_$i</code> so when i select <code>opt_4</code> i want to insert it before <code>opt</code> which is greater (its not always 5 it can be 73)</p>

<pre><code>function minus(id)
{
    var c = $('select#'+ id +' option:selected');
    var cities = $('select[name=cities] option');

    c.each(function(){
       var item = $(this);
       var current = parseInt($(this).attr('class').replace(/[^0-9]/g, ''));

       cities.each(function(){
           var next = parseInt($(this).attr('class').replace(/[^0-9]/g, ''));

           if(next &gt; current)
           {
               var next_item = $(this);
               return; // I dont know why this doesnt work ??
           }
       });
       /**
       if(previouse == 1)
       {
           $('select[name=cities] option:first').before(
                $('&lt;option&gt;&lt;/option&gt;')
                    .attr('value', current.val())
                    .attr('class', current.attr('class'))
                    .text(current.text())
           );    
       }
       else
       {
       */
           //$('select[name=cities] option[class=opt_'+ previouse +']').next()
           next_item.before(
                $('&lt;option&gt;&lt;/option&gt;')
                    .attr('value', current.val())
                    .attr('class', current.attr('class'))
                    .text(current.text())
           );
       //}
       $(this).remove();
    });
}
</code></pre>

<p>Is there better way to achive this ?? Than looping every time list in which i want to insert option to find greater class value ??</p>

<p><strong>Edit:</strong></p>

<pre><code>&lt;select id="a"&gt;
  &lt;option class="opt_3"&gt;a&lt;/option&gt;
&lt;/select&gt;

&lt;select id="b"&gt;
 &lt;option class="opt_1"&gt;c&lt;/option&gt;
 &lt;option class="opt_7"&gt;d&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>after clicking on button i want to remove option from list <code>a</code> and insert to list <code>b</code> but before <code>opt_7</code>. How to find option which has class greater than opt_3 ??</p>

<p><strong>SOULUTION</strong>
<a href="http://jsfiddle.net/Atm8V/6/" rel="nofollow">http://jsfiddle.net/Atm8V/6/</a> here is how it should work, thanks for all comments.</p>
