Dynamically make DOM element height equal

Most of the time we encounter a situation where our layout is disturbed due to uneven heights of the divs, spans or other elements having varying amount of content. This causes them to have variable height which in turn results in broken layout.

A quick and simple fix for such problem can be adjusting the height with javascript or jQuery.

assuming that ourĀ  content is enclosed in div having class “variable-height”, following script should do the trick

var maxHeight = Math.max.apply(null,
        return $(this).height();