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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:52:31+00:00 2026-05-23T14:52:31+00:00

I am trying to retrieve the body’s scrollHeight in order to reset the size

  • 0

I am trying to retrieve the body’s scrollHeight in order to reset the size of a div with id=”background1″. If in my external css I set that id to position:absolute the scrollHeight always returns 0. If I set it to position:relative scrollHeight gives me the correct value. There are of course many more selectors in the css one other of which is set to position:absolute – leaving it as such doesn’t change the above behavior. The code :

<script type="text/javascript">

  function getElement(elem)  {

     var art;

     if ( document.all ) {                  // this is the way old msie versions work      
       art = document.all[elem];  
     }
     else if ( document.layers ) {          // this is the way nn4 works    
       art = document.layers[elem];
     }
     else if ( document.getElementById ) {  // this is the way the standards work    
       art = document.getElementById( elem );
     }

     return art;
}

function toggleArticleDisplay(elem)  {

  var artArray = document.getElementsByTagName("article");

  for(var i = 0; i < artArray.length; i++)  {
     artArray[i].style.display = "none";
   }

   var art = getElement(elem);
   art.style.display = "block";

   var bg1 = document.getElementById("background1");
   bg1.style.height = "550px";  

   var b = document.getElementById("potoococha");

   alert(b.scrollHeight);

   bg1.style.height = (b.scrollHeight >= window.innerHeight) ? 
           (b.scrollHeight+20) + "px" : window.innerHeight + "px";
 }

</script>

</head>

<body id="potoococha" onLoad="toggleArticleDisplay('homeText')">

<div id="background1" style="height:615px;"/>

And now the css :

div#background1  {  position         : absolute;
                    left             : 45px;
                    top              : 0px;
                    z-index          : 1;
                    width            : 50px;
                    background-color : rgba(182,181,91,1.0); }

Merely changing that position to relative makes the javascript function return the correct scrollHeight but I need this as absolute for other reasons. Does scrollHeight not work if some element is absolutely positioned? As I said there is another later absolutely positioned element which doesn’t have any effect on scrollHeight‘s return value. Only this element which is the first child of the body element seems to be a problem. Any ideas?

  • 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-05-23T14:52:31+00:00Added an answer on May 23, 2026 at 2:52 pm

    This is kinda a dirty hack, but you could try to do this:

    bg1.style.position = "relative"; 
    
    var savedHeight = b.scrollHeight;
    
    bg1.style.position = "absolute";
    

    Not sure if that’ll work, but maybe give it a try.

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

Sidebar

Related Questions

I am trying to retrieve the attribute name and type that exist in an
I'm trying to retrieve data from a php file named return that just contains
I'm trying to open the System SMS application with a sms body that is
I am trying to delete the duplicate atrists that are displayed when I retrieve
I am trying to display JSON data that I retrieve from an ajax call
I'm trying to make a Python program that retrieves only the body text of
I am trying to retrieve a set of values from database and assigned it
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I am trying to retrieve a user on Sharepoint's user photo through the WSS
I'm trying to retrieve a file from a server using SFTP (as opposed to

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.