Sort a list based on class as well as values

Sort a list based on class as well as values

I need to do a sort of nested sorting.

  1. <ul class="nested">
  2.   <li class="a-group">4</li>
  3.   <li class="a-group">2</li>
  4.   <li class="a-group">1</li>
  5.   <li class="a-group">3</li>
  6.   
  7.   <li class="b-group">4</li>
  8.   <li class="b-group">2</li>
  9.   <li class="b-group">1</li>
  10.   <li class="b-group">3</li>
  11.   
  12.   <li class="c-group">4</li>
  13.   <li class="c-group">2</li>
  14.   <li class="c-group">1</li>
  15.   <li class="c-group">3</li>
  16. </ul>

So is there a way I could sort each value within each group, so that I end up with this result:

//Group A
1
2
3
4

//Group B
1
2
3
4

//Group C
1
2
3
4

//Group D
1
2
3
4

So far I only know the simple way of doing this, by sorting without taking each class (group) into account.

Here is a fiddle:  https://jsfiddle.net/nykswcxL/2/