I have the sorting order in a variable.
var sortorder = "Amazon,Soap,Drugstore,Walmart,Walgreens".split(',');
and my requirement is that it should be arranged in the above given order and if some div's id is not available in the array then it should be appended in the last. The code below is ordering data in the order but the problem is if the div id doesn't exist in the array then it's not moving that div to the last.
HTML
<div class="wtb_results_online right_results wtb_results_online_results_vantage">
<div class="results">
<h3><span>Online Retailers</span></h3>
<div class="result_item result_innerdv" id="axyz"><span class="year">axyz</span><a class="btn_pack_sizes" href="javascript:void(0);"></a></div>
<div class="result_item result_innerdv" id="Drugstore"><span class="year">Drugstore</span><a class="btn_pack_sizes" href="javascript:void(0);"></a></div>
<div class="result_item result_innerdv" id="Walgreens"><span class="year">Walgreens</span><a class="btn_pack_sizes" href="javascript:void(0);"></a></div>
<div class="result_item result_innerdv" id="flipcart"><span class="year">flipcart</span><a class="btn_pack_sizes" href="javascript:void(0);"></a></div>
<div class="result_item result_innerdv" id="Amazon"><span class="year">Amazon</span><a class="btn_pack_sizes" href="javascript:void(0);"></a></div>
<div class="result_item result_innerdv" id="Walmart"><span class="year">Walmart</span><a class="btn_pack_sizes" href="javascript:void(0);"></a></div>
</div>
</div>
jQuery
var sortorder = "Amazon,Soap,Drugstore,Walmart,Walgreens".split(',');
$.each(function(index,value){
$('.wtb_results_online_results_vantage .result').append($('.wtb_results_online_results_vantage .result'));
});
$('.wtb_results_online_results_vantage .results > div').each(function(){
if($.inArray($(this).attr('id'), sortorder)==-1){
$('.wtb_results_online_results_vantage .results').append($('.wtb_results_online_results_vantage .results'));
}
});
}).appendTo($('#container));, correct it to}).appendTo($('#container'));