hehe
hehe

Reputation: 75

How to change the select option order?

<select onchange=""class="product-custom-option" name="options[41]">
  <option value=""> -- selsect --</option>
  <option price="0" value="162">L</option>  
  <option price="0" value="163">M  </option> 
  <option price="0" value="164">S </option>  
 <option price="0" value="165">XL </option>

  </select>

now i want to chage the order as this: S M L XL .

$('.product-custom-option:option(3)').insertAfter('.product-custom-option:option(0)');
$('.product-custom-option:option(1)').insertBefore('.product-custom-option:option(4)');

i am sorry, i am a newbie of jquery, the above doesn't get that?

i want to get the new order like this:

  <option value=""> -- selsect --</option>
<option price="0" value="164">S </option> 

  <option price="0" value="163">M  </option> 
     <option price="0" value="162">L</option> 
 <option price="0" value="165">XL </option>

Upvotes: 3

Views: 16601

Answers (2)

atif
atif

Reputation: 1693

Or you can just replace the html of select element :

$('.product-custom-option').html('<option value=""> -- selsect --</option><option price="0" value="164">S </option><option price="0" value="163">M  </option><option price="0" value="162">L</option><option price="0" value="165">XL </option>');​

http://jsfiddle.net/746G9/

Upvotes: 2

JJJ
JJJ

Reputation: 33153

var options = $('.product-custom-option option' );

$( options[ 3 ] ).insertAfter( $( options[ 0 ] ) );
$( options[ 2 ] ).insertAfter( $( options[ 3 ] ) );

http://jsfiddle.net/ceduG/

But it's probably easier to sort it server-side if at all possible.

Upvotes: 11

Related Questions