I think there may be a new way to sort them without an attribute but I'm not getting it to work properly. Who can help me understand why?
Initially I create an array, I put the various elements in the correct order.
var order = [4,3,2,7,5,0,1,6,8];
var i = 0;
$.fn.formordina = function(selector){
(selector ? this.find(selector) : this).parent().each(function(){
$(this).children(selector).sort(function(){
return order[i++];
}).detach().appendTo(this);
});
return this;
};
$(".form-action ol").formordina('li');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
<div class="form-action">
<ol>
<li>banana</li>
<li>apple</li>
<li>tomato</li>
<li>kiwi</li>
<li>pear</li>
<li>peach</li>
<li>lemon</li>
<li>ginger</li>
<li>orange</li>
</ol>
</div>
.sort()can use a compare function, yet it's expecting-1,0, or1to be returned. Please clarify your request.