Home > Web Front-end > JS Tutorial > Get the maximum width or height of a set of elements JavaScript code

Get the maximum width or height of a set of elements JavaScript code

php中世界最好的语言
Release: 2018-03-16 16:12:31
Original
2315 people have browsed it

This time I will bring you the code to get the maximum width or height of a group of elementsJavaScript, what are the precautions for using JavaScript to get the maximum width or height of a group of elements, The following is a practical case, let’s take a look.

The following function is very useful for developers who need to perform dynamic typesetting.

var getMaxHeight = function ($elms) {  var maxHeight = 0;
  $elms.each(function () {    // In some cases you may want to use outerHeight() instead
    var height = $(this).height();    if (height > maxHeight) {
      maxHeight = height;
    }
  });  return maxHeight;
};
Copy after login

How to use:

$(elements).height( getMaxHeight($(elements)) );
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

JavaScript code snippet to determine whether a date is valid

Detailed explanation of Event Loop of Node.js

Detailed explanation of JavaScript timer

The above is the detailed content of Get the maximum width or height of a set of elements JavaScript code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template