如何按高度对DIV进行排序? [英] How to sort DIVs by height?
本文介绍了如何按高度对DIV进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个 div
s,我想按高度从大到小排序。
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?
推荐答案
这很简单。使用 .sort()
:
It's quite simple. Use .sort()
:
$('div').sort(function (a, b) {
return $(a).height() > $(b).height() ? 1 : -1;
}).appendTo('body');
代码: http://jsfiddle.net/fEdFt/2/
这篇关于如何按高度对DIV进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文