jQuery Equal Height Divs Plugin

jQuery Equal Height Divs Plugin Preview

jQuery Equal Height Divs Plugin Preview

Description

Ever had 2 HTML Divs that you wish they would be just of the same height regardless of their content? Well, jQuery Equal Height Divs Fix is the right solution for you then as it will calculate both divs’s height and then examines which div is taller. Then it will assign the bigger height value to the shortest one.
The examined Divs don’t have to be next to each other, they can be anywhere in the page.
Please make sure that both Divs have the same top/bottom padding and margin values.
The solution was tested successfully on the following browsers: Internet Explorer, Firefox, and Chrome.
How tuse:

Ever had 2 HTML Divs that you wish they would be just of the same height regardless of their content? Well, jQuery Equal Height Divs Plugin is the right solution for you then, as it will calculate both divs’ height and then examines which div is taller. Then it will assign the bigger height value to the shortest one.

The examined Divs don’t have to be next to each other, they can be anywhere in the page.

Please make sure that both Divs have the same top/bottom padding and margin values.

The solution was tested successfully on the following browsers: Internet Explorer, Firefox, and Chrome.

Updates:

[02/08/2010] Fixing the resize window bug: The code will keep running while the browser’s window is being resized or after maximizing the window.

How to use

1- Copy the plugin file called: “jQueryEqualHeight.js” into the Javascript folder on your website.

2- Since the plugin only works if you call it inside the HTML page then you must call it at the head of the page as follows:

<script type=”text/javascript” src=”javascript/jQueryEqualHeight.js”></script>

3- Don’t forget to call the jQuery file before calling the jQueryEqualHeightFix as well:

<script type=”text/javascript” src=”javascript/jquery-1.4.2.min.js”></script>

You will find the latest up to the date of creating this fix jQuery library file under the demo folder attached with this file.

4- Open the plugin file: jQueryEqualHeightFix.js using your favorite Javascript editor (or simply Notepad)

5- Scroll down to line 10 and 11 and change the Div id or class names as per your HTML divs that you wish to be equal as shown in the demo files or as per the example below:

Example:

In your HTML file you have 2 Divs. One that is called <div id=”sideNav”> and the other one is called <div id=”mainContent”>.

In that case, at your jQueryEqualHeight.js file, change line 22 and 23 as follows:

var firstDiv=’#sideNav’;

var firstDiv=’#mainContent’;

That’s all, if you still need any help don’t hesitate to leave a comment.

Continue reading with more related articles:

No related posts.

  • Delicious
  • Facebook
  • Digg
  • Reddit
  • StumbleUpon
  • Twitter

2 Comments to “jQuery Equal Height Divs Plugin”

  1. Martin Ruston 2 August 2010 at 1:08 pm #

    Hi Ayman

    I would like to use your equal heights plug-in in the redesign of my local
    history website http://www.rushtonspencer.info. However as I have a fixed width
    sidebar and a fluid main content area I need the script to be executed again
    when the browser is resized, is it possible to add this functionality to
    your plug-in and if so how?

    Thanking you in advance.

  2. Ayman Aboulnasr 2 August 2010 at 1:12 pm #

    Hi Martin,

    I have just updated the jQuery Equal Height Divs Plugin to fix the heights of both divs while or after the browser’s window is being resized.

    Download the latest version of the plugin from the Download link above.

    Thank you.


Leave a Reply