-1

Don't have any idea how to sort the list of items based on the three priorities.

I have an existing below list of items. I have successfully sorted them in alphabetical order using a data-title attribute. Now I want also to sort them into priorities if the user wants to. The priorities are 1. driving 2. idle 3. stop. So I just use value as my data. Any idea how can I achieve this priority sorting?

<ul id='myUl'>
<li class='myLi' data-title='ERE-8792' value='idle'>ERE-8792</li> 
<li class='myLi' data-title='ABA-1102' value='stop'>ABA-1102</li> 
<li class='myLi' data-title='VDW-5486' value='stop'>VDW-5486</li> 
<li class='myLi' data-title='DRF-5896' value='driving'>DRF-5896</li> 
</ul>

The result should be:

  • DRF-5896
  • ERE-8792
  • ABA-1102
  • VDW-5486
  • See [Javascript - sort array based on another array](/q/13304543/4642212), [Sorting a list by data-attribute](/q/32199368/4642212), and [How to sort an array of objects by multiple fields?](/q/6913512/4642212). [Validate your HTML](//validator.nu). `
  • ` elements do not have a `value` attribute.
  • – Sebastian Simon Feb 09 '23 at 02:40