I have an li element with 2 data attributes, basically I want to sort out first the data-arrange attribute, this is the element
<ul>
<li data-arrange="2" data-rdays="100">John</li>
<li data-arrange="1" data-rdays="300">Paul</li>
<li data-arrange="1" data-rdays="500">Bryan</li>
<li data-arrange="3" data-rdays="240">Mark</li>
<li data-arrange="3" data-rdays="500">Victor</li>
<li data-arrange="4" data-rdays="200">Tess</li>
</ul>
so from the given element it should return like this
data-arrange attribute value arrangement
1
1
2
3
3
4
then I want to sort it with data-rdays attribute from highest to lowest based on data-arrange attribute arrangement so it will look like something like this
1 500
1 300
2 100
3 500
3 240
4 200
result should be like this
Bryan
Paul
John
Victor
Mark
Tess
This is what I've tried so far:
function sort_li(a, b){
return ($(b).data('arrange')) < ($(a).data('arrange')) ? 1 : -1;
/* Other return staments that I've tried
return ($(a).data('rdays') && $(b).data('arrange')) < ($(b).data('rdays')
&& $(a).data('arrange')) ? 1 : -1;
return new Date($(a).data("date")) - new Date($(b).data("date")); */
}
Is there a way how can I accomplish this? Thank you.