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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:17:58+00:00 2026-06-13T21:17:58+00:00

I am trying to set the height and width of a div through javascript

  • 0

I am trying to set the height and width of a div through javascript and to no avail. I have tried numerous things and had no luck so far please advise me where i am going wrong? I thought this would just be straight forward…

I am not sure what the problem is here, I cannot use CSS in this case to set the variables i need to do it in JavaScript that is another topic all together though.

<div id="demo">Demo Div</div>

<script>
    var test = document.getElementById("demo");
    test.style.width = "100px";
    test.style.height = "100px";
    test.style.cssText = 'border:1px solid black;'
</script>

Thank you in advance.(I am open to a jQuery alternative as well)

-Epik-

  • 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-13T21:17:59+00:00Added an answer on June 13, 2026 at 9:17 pm

    The problem is that your last line is setting cssText, which overwrites the styles set on the first two lines rather than adding to them. Try this instead:

    var test = document.getElementById("demo");
    test.style.width = "100px";
    test.style.height = "100px";
    test.style.border = '1px solid black'
    

    Demo: http://jsfiddle.net/ZtyfB/

    And since you mentioned jQuery, here’s one way you could use it to do the same thing:

    $("#demo").css({
        width : "100px",
        height : "100px",
        border : '1px solid black'
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set the width & height property of an image element i've
I've been trying to get image-loading dynamically- size dynamically to set wrapper div height
I am trying to set the same height of a group of div's that
I'm trying to set an input box with a specific internal height, and I'm
im trying to set the height of two divs on my page, because my
I'm trying to set the Height of a ComboBox in C#.NET CF / WinCE6.
I've been trying in vain to set the height on a container. I've been
So I am trying to use the CSS hack to set the max-height for
I'm trying to center a div, here is what i came up so far:
I'm trying to get dynamic height with below paragraph. <td> <b>audio systems</b> <br> <div

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.