开发者

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

开发者 https://www.devze.com 2022-12-22 16:17 出处:网络
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.

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 stat开发者_开发技巧e.

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!


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号