Skip to content

Instantly share code, notes, and snippets.

@yckart
Created November 10, 2012 14:36
Show Gist options
  • Select an option

  • Save yckart/4051281 to your computer and use it in GitHub Desktop.

Select an option

Save yckart/4051281 to your computer and use it in GitHub Desktop.
Get the biggest/heighest element
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<style>
ul {
float:left;
margin: 5px 0 0 5px;
padding: 5px;
color: white;
font-family: sans-serif;
background-color: yellowgreen
}
</style>
<title>Get the biggest/heighest element</title>
</head>
<body>
<ul>
<li>Line1</li>
</ul>
<ul>
<li>Line1</li>
<li>Line2</li>
<li>Line3</li>
</ul>
<ul>
<li>Line1</li>
<li>Line2</li>
<li>Line3</li>
</ul>
<script src='http://code.jquery.com/jquery-1.8.2.js'></script>
<script>
$(function($) {
var max = $.makeArray($('ul')).sort(function(a, b) {
return (parseInt($(b).css('height'), 10) || 1) - (parseInt($(a).css('height'), 10) || 1);
}).shift();
$(max).css('background-color', 'orange');
});
</script>
</body>
</html>​
@yckart
Copy link
Copy Markdown
Author

yckart commented Nov 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment