Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8232897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:58:20+00:00 2026-06-07T17:58:20+00:00

I am loading an equalheights function on browser load if the window is wider

  • 0

I am loading an equalheights function on browser load if the window is wider than ‘x’. I am also wanting to do another check for ‘x’ on browser resize to ‘retest’ if I want to add my function.

Not sure how to do this:

// global variables
var compareWidthColumn, //previous width used for comparison
detectorColumn, //the element used to compare changes
smallScreenColumn, // Size of maximum width of single column media query
jQuery(document).ready(function($) {
    //set the initial values
    detectorColumn = jQuery('.js');
    compareWidthColumn = detectorColumn.width();
    smallScreenColumn = '481';

    if ($(window).width() > smallScreenColumn) {
        $('#sidebar_right').equalHeights();
    }    

    jQuery(window).resize(function() {
        //compare everytime the window resize event fires
        if (detectorColumn.width() != compareWidthColumn) {

            //a change has occurred so update the comparison variable
            compareWidthColumn = detector.width();

            if (compareWidthColumn > smallScreenColumn) {
                $('#sidebar_right').equalHeights();
            }
        }

    });
});

The entire concept is that I am only wanting to apply ‘equalHeights’ if the browser is wider than 481px. This is being applied to a fluid layout and I expect the user to be resizing their browser, hence the call to resize.

Problem:
The initial load works right, the equalHeight is only called if the window is wider than 481px. The problem is if the user starts with the browser wider than 481 px, and shrinks it down, the equalHeight is not being removed.

How do I fix this?
*my attempt at learning jQuery, so kinda new.

EDIT
It was mentioned in the comments that I had different things being measured so I tried this as well:

jQuery(document).ready(function($) {
    //set the initial values
    detectorColumn = jQuery('.js');
    compareWidthColumn = detectorColumn.width();
    smallScreenColumn = '481';

    if ($(window).width() > smallScreenColumn) {
        $('#sidebar_right').equalHeights();
    }    

    jQuery(window).resize(function() {

            if ($(window).width() > smallScreenColumn) {
                $('#sidebar_right').equalHeights();
            }
    });
});

I am still having the issue of the equalHeights not ‘remeasuring’ the elements on screen resize, and not removing itself if the screen is less than 480px.

EDIT 2*
I should mention the reason I was using 2 different measurements is before this script, i am declaring some global variables:

This is above my script at the top of my jquery page.

// global variables
var compareWidthColumn, //previous width used for comparison
detectorColumn, //the element used to compare changes
smallScreenColumn, // Size of maximum width of single column media query

My idea was that if I declared those outside of the function that they would be storing the values. Then when the screen resizes, it would be comparing the new value to the global value, then if there is a change, redo the function.

Is that bad logic?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:58:22+00:00Added an answer on June 7, 2026 at 5:58 pm

    Maybe I’m missing something here but the following simple approach should work (well at least it will do something):

    $(function() {
        var $sidebar_right = $('#sidebar_right'),
            smallScreenColumn = 481;
        $(window).on('resize', function() {
            $sidebar_right.height('auto');//remove previously applied equalHeights.
            if($(window).width() > smallScreenColumn) {
                $sidebar_right.equalHeights();
            }
        }).trigger('resize');
    });
    

    I have assumed .height('auto') to be the correct way to remove previously applied .equalHeights() based on a comment here.

    You may wish to reintroduce detectorColumn etc. but, at least superficially, it appears to be an unnecessary complication.

    I still don’t understand how applying .equalHeights() to the container manages to affect the divs contained within it when all the examples in the documentation are of the form $(classSelector).equalHeights();. If my understanding is correct, then something like $('#sidebar_right > div') would be more appropriate (ie. all sidebar_right’s child divs).

    EDIT: My bad. By setting .equalHeights() on a container element, it automatically “loops through the top-level child nodes”. See link in @shaWn’s comment below.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When loading a html page using JQuery load, I also need to call another
On loading the page I want to pass a value to my javascript function
After loading a PHP template (using jQuery's load function), this simple script won't make
Before loading jquery.js , I have a simple: window.onload = function (){ /*dosomething*/ }
After loading an internal div (#book_table) via ajax, I want to resize the width
When loading Mootools More from my server, Android Stock Browser (froyo 2.2 and gingerbread
When loading one view in to another with jquery i do that. In file
Loading Help or clicking F1 in Visual Studio is horribly slow to load and
Some loading routines in my program takes to long to complete. I want a
Does loading unimportant data right after page load using AJAX help load the web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.