How to sort DIVs by height?
问题 I have three div s and I want to sort them by height, from largest to smallest. <div>smallest</div> <div>largest</div> <div>middle</div> Any idea? 回答1: It's quite simple. Use .sort(): $('div').sort(function (a, b) { return $(a).height() > $(b).height() ? 1 : -1; }).appendTo('body'); Code: http://jsfiddle.net/fEdFt/2/ 回答2: Since jQuery returns an array, you can use the sort method on array to reorder the elements. Once they are sorted in the proper order, you can then remove them from the DOM