Reputation: 75
<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
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>');
Upvotes: 2
Reputation: 33153
var options = $('.product-custom-option option' );
$( options[ 3 ] ).insertAfter( $( options[ 0 ] ) );
$( options[ 2 ] ).insertAfter( $( options[ 3 ] ) );
But it's probably easier to sort it server-side if at all possible.
Upvotes: 11