Generic sorting of DOM objects