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 8819701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:25:39+00:00 2026-06-14T05:25:39+00:00

I have several functions running in my main js file and after I added

  • 0

I have several functions running in my main js file and after I added two lines to one of them, this error appears. The odd thing is, the error references a variable in one of the other functions which is entirely unrelated to the one being called.

Here is the function that I changed:

window.onresize = function(){
    var timeOut = null;
    if(timeOut != null) clearTimeout(timeOut);
        setTimeout(expandWrapper, 500);
}

var expandWrapper = function(){ 
    //var eContent = document.getElementById("content");
    var eContent = document.getElementById("main-content");
    var eMainContent = document.getElementById("column-1");
    var elayoutArea = document.getElementById("layout-column_column-1");
    var eFooter = document.getElementById("footer");
    //var dScrollb = $(".dataTables_scrollBody");
    var leftWrapper = document.getElementById("left-links-wrapper");
    var contentEnd = eMainContent.clientHeight + eMainContent.offsetTop;

    if(document.documentElement.clientHeight >= (eContent.offsetTop  + elayoutArea.clientHeight + eFooter.clientHeight)){       
        eMainContent.style.height = document.documentElement.clientHeight - eContent.offsetTop - eFooter.clientHeight -1 + "px";
        added line--> leftWrapper.style.height = document.documentElement.clientHeight - eContent.offsetTop - eFooter.clientHeight -1 + "px";
        //console.log("primary condition");
    } else {
        eMainContent.style.height = ($(window).height()); //elayoutArea.clientHeight + "px";
        added line-->leftWrapper.style.height = eMainContent.offsetHeight + "px";
        //console.log("fallback");
    }   
}

I’ve pointed out the two added lines, located in the if statement and beginning with “leftWrapper.style.height“. Incidentally, while eMainContent element appears on all pages, leftWrapper element only appears on certain pages and the error appears only on those page where leftWrapper does not exist.

I’m thinking this is where the problem lies: the javascript flips out because it can’t perform the action I’ve requested on an element that does not exist on a particular page.

Assuming this is the problem, how could I rewrite this to alleviate this error but modify leftWrapper on the pages where it exists?

  • 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-14T05:25:40+00:00Added an answer on June 14, 2026 at 5:25 am

    The problem, as you point out, is that calling getElementById will return null if you pass in an identifier not present in the DOM.

    For cases like these where you’re working with an object that could be null or undefined, you can simply do the following:

    if (possiblyNullOrUndefinedVariable) {
      possiblyNullOrUndefinedVariable.doSomething();
    }
    

    This could also be shortened to:

    possiblyNullOrUndefinedVariable && possiblyNullOrUndefinedVariable.doSomething();
    

    taking advantage of the short-circuiting of the && operator.

    One caveat worth noting is that this won’t behave as you’d expect for all variables. 0 and '' are also falsey values. If you know you’ll be dealing with strings or numbers, you can instead do something like:

    if (possiblyNullOrUndefinedVariable != null && possiblyNullOrUndefinedVariable != undefined) {
      possiblyNullOrUndefinedVariable.doSomething();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this program, I have coded in several formulae and for one formula I
I have a several functions which are quite large, and are only used in
I have several onmouseover events (combination of javascript functions and jquery accordions) but they
I have a Bourne Shell script that has several functions in it, and allows
I have developed several general purpose script functions, for Google Spreadsheet apps. Currently I
I have a certain loop occurring several times in various functions in my code.
I have noticed that Google Toolbox for Mac replaces several SQLite built-in functions (LOWER/UPPER,
My application has several independent top-level windows, which all have completely different functions/workflows. I
In a C project, I have a main() function in several files. When I
I've been running Python scripts that make several calls to some functions, say F1(x)

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.