Skip to content

Instantly share code, notes, and snippets.

@alvinsj
Created March 9, 2012 08:34
Show Gist options
  • Save alvinsj/2005664 to your computer and use it in GitHub Desktop.
Save alvinsj/2005664 to your computer and use it in GitHub Desktop.
[jquery] sort list items by words (e.g.data-name)
$.sort_by_words = (ulClass, name) ->
$("ul.#{ulClass} li").sort (a, b) ->
if $(a).data("#{name}").toLowerCase() > $(b).data("#{name}").toLowerCase() then 1 else -1
.appendTo("ul.#{ulClass}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment