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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:41:28+00:00 2026-05-12T10:41:28+00:00

How do I dynamically change the height of a div. Why does this not

  • 0

How do I dynamically change the height of a div.

Why does this not work:

 var priceBarElement = $("priceBar");
 priceBarElement.style.height = request.responseText+"px";

Which I hope to use to change the priceBar div which is given by this line further down.

 <div id="priceBar" style="width:28px;margin-top:20px;background:#F00"></div>

I am getting a correct value for the height being sent to the page, which I can see since I print it out. However I can’t seem to use the value to change the height of the priceBar div.

I am using Comets to send the “heights” hence there is no explicit action which requests a new “height”.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.astheymove.util.ApplicationPathUtils"%><html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Comet Weather</title>
    <script src="javascript/prototype.js" type="text/javascript"></script>
    <script src="javascript/scriptaculous.js" type="text/javascript"></script>

    <script type="text/javascript">
        function go(){
            var url = '<%= ApplicationPathUtils.getApplicationPath(pageContext) + "/prices" %>';
            var request =  new XMLHttpRequest();
            request.open("GET", url, true);
            request.setRequestHeader("Content-Type","application/x-javascript;");
            request.onreadystatechange = function() {
                if (request.readyState == 4) {
                    if (request.status == 200){
                        if (request.responseText) {
                            var forecastsElement = $("forecasts"); 
                            forecastsElement.innerHTML = request.responseText;
                            var priceBarElement = $("priceBar");
                            priceBarElement.style.height = request.responseText+"px";
                            // highlight it
                            //new Effect.Highlight(forecastsElement, { startcolor: '#C0C0C0',
                            //  endcolor: '#ffffff' });
                        }
                    }
                    // not to highlight too often
                    //setTimeout("go();",1000);
                    go();                                
                }
            };
            request.send(null);
        }
    </script>
</head>
<body>
    <h1>Rapid Fire Weather</h1>
    <input type="button" onclick="go()" value="Go!"></input>
    <div id="forecasts" style="padding:10px; border:1px solid #ccc; background:#ffffff;">
        Weather forecasts!
    </div>
    <div id="pricesPanel" style="height:100px;">
                <div id="priceBar" style="width:28px;margin-top:20px;background:#F00"></div>
    </div>
</body>
</html>
  • 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-12T10:41:28+00:00Added an answer on May 12, 2026 at 10:41 am

    You are trying to set the height of the node before the DOM is ready. It’s sometimes tricky when dealing with an XHR, because you want to call that XHR right away, but sometimes the callback from it happens before the page is loaded. Initially, put the XHR function inside a window.onload function (or the Prototype DOM Ready equivalent). If that fixes the problem, you can try doing the XHR first and test if the DOM is ready or not – f it is, set it, if not, defer the function.

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

Sidebar

Ask A Question

Stats

  • Questions 195k
  • Answers 195k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Answering myself: I forgot to release a previous statement in… May 12, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer What are you trying to achieve by making it use… May 12, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer The short answer is that you can't make it a… May 12, 2026 at 7:00 pm

Related Questions

Possible Duplicate: Change CSS Dynamically I need to change the height of a div
Currently, I'm able to load in a static sized texture which I have created.
I want to insert a bezier spline into my Canvas by this code <mx:Canvas
I have c++ code that attempts to dynamically allocate a 2d array of bytes

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.