S16
S16

Reputation: 2995

jQuery sort unordered list alphabetically and numerically based on inner element value(s)

Code as reference:

http://jsbin.com/aboca3/2/edit

In this example above (thank you SLaks) I am truncating long unordered lists and providing a toggle link to view the entire thing.

The issue, from a usability standpoint, is that as a full list, it is best sorted alphabetically, which will be the default sort order (the source order). As a short/truncated list, they are most usefully ordered by the magnitude these options will effect the results, in this case the number in the <em> element.

So working with the code I already have, I would like to re-order the list numerically by <em> element (highest to lowest), and then when the list is toggled, re-order it alphabetically/numerically based on toggle state.

I'm having a hell of a time trying to wrap this in to an associative array so I'd love a fresh perspective on how to handle this.

Thank you!

Upvotes: 2

Views: 3492

Answers (2)

S16
S16

Reputation: 2995

Using petersendidit's code I was able to acheive exactly the result I was looking for. You can view it here:

http://jsbin.com/aboca3/7/edit

Upvotes: 0

PetersenDidIt
PetersenDidIt

Reputation: 25620

This should do it for you: http://jsbin.com/aboca3/5/edit

Upvotes: 4

Related Questions