?
Solved

jQuery: height of highest matching element

Posted on 2011-10-26
2
Medium Priority
?
422 Views
Last Modified: 2012-05-12
Using jQuery, how can I get the height of the highest matching element?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {

 alert('The highest div.accordionContent is ??? px high');

});
</script>

</head>
<body>
<div class="accordion">
 <div class="accordionButton">
 <strong>Item 1</strong>
 </div>
 <div class="accordionContent">
 <p>
 Convallis dignissim. Proin ultricies.
 </p>
 </div>
 <div class="accordionButton">
 <strong>Item 2</strong>
 </div>
 <div class="accordionContent">
 <p>
 Vestibulum aliquam diam ac metus convallis dignissim. Proin ultricies
 purus et dui hendrerit euismod nec et nunc. Nullam non quam dui, id aliquet
 metus. Nulla rhoncus eleifend bibendum. Morbi tempus eleifend tincidunt.
 Suspendisse venenatis, libero ac hendrerit facilisis, nunc nisl consectetur
 nisl, a lobortis nibh leo et nulla. Cras a ornare elit. Aenean a facilisis
 nisl. Etiam feugiat consequat sapien, a rhoncus lorem ullamcorper sed.
 Etiam placerat convallis leo at condimentum. Aliquam condimentum cursus
 metus, sit amet semper quam eleifend quis. Vivamus posuere placerat urna,
 ut adipiscing nibh iaculis sit amet. Pellentesque iaculis tincidunt diam,
 ac porta metus ornare sed.
 </p>
 </div>
 <div class="accordionButton">
 <strong>Item 3</strong>
 </div>
 <div class="accordionContent">
 <p>
 Curabitur vehicula, nisi non volutpat dictum, mauris est tristique eros, 
 eu ornare nisi nisl non odio. Vivamus posuere enim sed nibh aliquam pretium. 
 Fusce in pulvinar metus. Nulla tempor metus cursus purus cursus ut varius nibh cursus. 
 Nulla rhoncus eleifend bibendum. Morbi tempus eleifend tincidunt.
 Pellentesque iaculis tincidunt diam, ac porta metus ornare sed.
 </p>
 </div>
 <div class="accordionButton">
 <strong>Item 4</strong>
 </div>
 <div class="accordionContent">
 <p>
 Hello world.
 </p>
 </div>
</div>
<div class="c"></div>
</body>
</html>

Open in new window

0
Comment
Question by:hankknight
2 Comments
 
LVL 5

Accepted Solution

by:
DerSpinner earned 1000 total points
ID: 37030929
Try something like this:

var maxHeight = 0;
$('.accordionContent').each(function() {
   var acHeight = $(this).height();
   if (maxHeight < acHeight) {
      maxHeight = acHeight;
   }
);

alert('The highest div.accordionContent is' + maxHeight + ' px high');

Open in new window


BR, Marcus
0
 
LVL 61

Assisted Solution

by:HainKurt
HainKurt earned 1000 total points
ID: 37031146
i came up with a similar function :)


$(document).ready(function() {
  var h=0;
  $(".accordion .accordionContent p").each( function(){h=$(this).height()>h?$(this).height():h;} );
  alert('The highest div.accordionContent is ' + h + ' px high');
});

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question