I want to find out that out of the given <li>
which li
has the maximum height?
how do i write such function?
If there are n <li>
elements of different size, content and height. I want to figure out the maximum height of the biggest <li>
element.
height() method is recommended when an element's height needs to be used in a mathematical calculation. This method is also able to find the height of the window and document. $( document ). height();
offsetHeight read-only property returns the height of an element, including vertical padding and borders, as an integer. Typically, offsetHeight is a measurement in pixels of the element's CSS height, including any borders, padding, and horizontal scrollbars (if rendered).
jQuery height() Method The height() method sets or returns the height of the selected elements. When this method is used to return height, it returns the height of the FIRST matched element. When this method is used to set height, it sets the height of ALL matched elements.
Try this:
var max = -1;
$("li").each(function() {
var h = $(this).height();
max = h > max ? h : max;
});
alert(max);
If you want a one liner
var max = Math.max.apply(Math, $("li").map(function() { return $(this).height(); }))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With