user1519730
user1519730

Reputation: 5

jQuery add variable

I found a script here that equalizes the height of divs in a row (bootstrap). How do you add 20 for instance to the new height it calculates?

Here is the script and a jsFiddle: http://jsfiddle.net/MVP3C/

$('.well, .alert').height(function () {
    var h = _.max($(this).closest('.row').find('.well, .alert'), function (elem, index, list) {
        return $(elem).height();
    });
    return $(h).height();
});

Upvotes: 0

Views: 90

Answers (1)

Andrew Sklyarevsky
Andrew Sklyarevsky

Reputation: 2135

Try the following snippet:

var HeightIncrement = 20; // the increment you need

var h = _.max($('.row').
    find('.well, .alert'),
    function (elem, index, list) {
        return $(elem).height();
    });
var maxHeight = $(h).height();

$('.well, .alert').height(function () {
    return maxHeight + HeightIncrement;
});

In essence, it is just needed to calculate the common height beforehand (the maxHeight variable), and then run the .height(...) function with an incremented common height value.

http://jsfiddle.net/pJ8zQ/

Upvotes: 2

Related Questions