I am having issues on sorting based on array. Let's say I have something like this:
HTML:
<button onClick="sortfunc();">Sort</button>
<ul id="sortable">
<li id="a">is </li>
<li id="b">awesome</li>
<li id="c">very </li>
<li id="d">javascript </li>
<li id="e">hard </li>
<li id="f">but </li>
</ul>
Now I want to use an external button to sort it out and sort final value equal to d a c e f b order.
Javascript:
$(function() {
$( "#sortable" ).sortable();
});
function sortfunc() {
var idsInOrder = $("#sortable").sortable("toArray");
console.log(idsInOrder);
//Print: ["a", "b", "c", "d", "e", "f"]
var sorttoarray = ["d","a","c","e","f","b"];
//Do something here to sort the ul li to match sorttoarray
}
I print out the array but it is not in the order as expected. Is it possible to use external button to sort out the above sortable to the id as indicated?
EDIT so id starts with letter.