Created
July 20, 2011 21:18
-
-
Save AdamTReineke/1095961 to your computer and use it in GitHub Desktop.
Sort all definition lists (DL) on a page alphabetically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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