Home  >  Article  >  Web Front-end  >  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中世界最好的语言
php中世界最好的语言Original
2018-03-16 16:12:312283browse

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;
};

How to use:

$(elements).height( getMaxHeight($(elements)) );

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!

Statement:
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