Skip to content

Instantly share code, notes, and snippets.

@AdamTReineke
Created July 20, 2011 21:18
Show Gist options
  • Save AdamTReineke/1095961 to your computer and use it in GitHub Desktop.
Save AdamTReineke/1095961 to your computer and use it in GitHub Desktop.
Sort all definition lists (DL) on a page alphabetically
// jQuery code to sort all definition lists on a page alphabetically, assuming terms and definitions alternate. Place in $(document).ready(function(){ });
$("dl").each(function() {
$(this).children("dt").sort(function(a, b){
return a.innerHTML.toUpperCase() > b.innerHTML.toUpperCase() ? 1 : -1;
}).each(function() {
var dd = $(this).next("dd");
$(this).appendTo($(this).parent());
dd.appendTo(dd.parent());
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment