Hi I am wanting to sort a list of links to match an array order:
List:
<a href="" data-value="10">10</a>
<a href="" data-value="6">6</a>
<a href="" data-value="8">8</a>
...
<a href="" data-value="m">M</a>
<a href="" data-value="s">S</a>
Array for Ordering:
['6', '8', '10', '12', '14', 'xs', 's', 'm', 'l', 'xl', 'xxl']
I am using the following which sorts the text options fine, but not the numerical ones:
(function () {
var order = ['6', '8', '10', '12', '14', 'xs', 's', 'm', 'l', 'xl', 'xxl'];
var $wrapper = $('.size-filter');
$wrapper.find('a').sort(function (a, b) {
var aSize = $(a).data('value'), bSize = $(b).data('value');
return order.indexOf(aSize) - order.indexOf(bSize);
}).appendTo($wrapper);
})();
How can I adjust this sorting function or rewrite it so it sorts both text and numerical size options?
data-valueor can there be multiple? If the latter, what should determine the secondary sorting?