I need help completing my feature, I think I have a good start but some troubles finishing it!
I have multiple divs on my page and each one is containing a select box. I have a button to sort the divs based on the value of each select.
Here is the Fiddle with my code and some comments.
I will also put the code here:
JS
$('.sort-priority').click(function(){
var priorityValues = $('select.js-priority').val();
var arr = [];
var i= 0;
$('select.js-priority').each(function() {
arr[i++] = parseInt(this.value);
});
console.log(arr); //Get an array of all my select default values [2, 0, 1, 0]
arr.sort();
console.log(arr); //Sorted the array the way I want, so all the 0 values first... [0, 0, 1, 2]
/* I cant figure out out how to rearrange my divs on the page, so I show the divs in the order of the sorted array of select values.
In this example the first box would be box2 (select value of 0), then box4 (select value of 0), box3 (select value of 1) and finally box1 (select value of 2).*/
});
Im a bit lost on how to manipulate my html to change the box ordering based on my array ?! If anyone could help, would be much appreciated!