from http://trentrichardson.com/2013/12/16/sort-dom-elements-jquery/
I wanted to share a quick snippet that I worked up for a unique scenario. Occasionally you want to sort or display DOM elements in a certain order. For instance, what if you have a list of names. A feature of your site may be that you can sort the list by first name, or last name. There are a few ways you can approach this.
One approach may be using a javascript framework like Backbone or Angular, where you have a model and collection. Then simply sort the collection, magic happens, and your list is essentially regenerated.
The other could be that you’re not using a framework and not want to regenerate the entire list, but to move the nodes. It is actually rather simple. Lets say you have a list like the following: