0

I'm trying to call an equal height function using $(document).ready, though I had to call it like this, because I was getting a Type Error.

jQuery(function($) {
$(".cols").equalHeights();
});

Instead of

$(document).ready(function() {
    $(".cols").equalHeights();
});

This works great, but I would also like the plugin to run when the page is resized, (so it will adjust to the content overflow). Below is the resize call, how can I combine it with the document ready call?

$(".cols").resize(function(){
    $(".cols").equalHeights();
});
James Montagne
  • 77,516
  • 14
  • 110
  • 130
Joe_Maker
  • 131
  • 7

2 Answers2

6

How about:

(function($) {
    $(document).ready(function() {
        var cols = $(".cols");

        cols.resize(function(){
            cols.equalHeights();
        });

        cols.trigger('resize');
    });
})(jQuery);
Lloyd
  • 29,197
  • 4
  • 84
  • 98
1

This code calls the jquery equalHeights plugin found here: http://www.cssnewbie.com/equalheights-jquery-plugin/#.UcOQiPm1HOU


It now works when the window is resized.


(function ($) {
    $(document).ready(function () {
       var cols = $(".cols");
       cols.resize(function () {
           cols.equalHeights();
        });
        cols.trigger('resize');
    });
      $(window).resize(function(){
            $(".cols").css("height","auto").equalHeights(); // maybe reset the height?
      }).resize() // trigger a resize to start off everything.
})(jQuery);
Joe_Maker
  • 131
  • 7