Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find shortest div with JQuery

<div id="c1" class="features" style="height:100px;width:100px;"></div>
<div id="c2" class="features" style="height:120px;width:100px;"></div>
<div id="c3" class="features" style="height:90px;width:100px;"></div>
<div...> 

How do I use JQuery to find the shortest div?

For example, the above would result in div id="c3" because its height is 90px.

like image 300
nash anderson Avatar asked Nov 10 '12 03:11

nash anderson


1 Answers

var shortest = [].reduce.call($(".features"), function(sml, cur) {
    return $(sml).height() < $(cur).height() ? sml : cur;
});
like image 122
I Hate Lazy Avatar answered Sep 28 '22 01:09

I Hate Lazy