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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:04:15+00:00 2026-06-09T18:04:15+00:00

EDIT: Directly below is the new code. Below that is the original question. I

  • 0

EDIT: Directly below is the new code. Below that is the original question. I am asking for help for what is wrong with this code, as, in my week-old eyes, it seems fine.

function creatediv(){

    for (i=1;i<13;i++){
        var newcovdiv = document.createElement('div');
        newcovdiv.setAttribute('id',"cover_"+i);
        newcovdiv.style.width="900px";
        newcovdiv.style.height="25px";
        newcovdiv.style.position="relative";
        newcovdiv.style.left="0px";
        newcovdiv.style.top=(i-1)*25+"px";
        newcovdiv.style.background="#FFFFFF";
        newcovdiv.style.display="none";
        document.getElementById('staff').appendChild(newcovdiv);
    }

    var newstaffdiv = document.createElement('div');
    newstaffdiv.setAttribute('id',"staff_sub");
    newstaffdiv.style.width="900px";
    newstaffdiv.style.height="300px";
    newstaffdiv.style.position="relative";
    newstaffdiv.style.left="0px";
    newstaffdiv.style.top="0px";
    newstaffdiv.style.backgroundImage="url(../images/staff_sub.png)";
    newstaffdiv.style.display="none";
    document.getElementbyId('staff').appendChild(newstaffdiv);

    for (i=13;i<101;i++){
        var newcovrdiv = document.createElement('div');
        newcovrdiv.setAttribute('id',"cover_"+i);
        newcovrdiv.style.width="900px";
        newcovrdiv.style.height="25px";
        newcovrdiv.style.position="relative";
        newcovrdiv.style.left="0px";
        newcovrdiv.style.top=(i-1)*25+"px";
        newcovrdiv.style.background="#FFFFFF";
        newcovrdiv.style.display="none";
        document.getElementById('paper').appendChild(newcovrdiv);
    }

}

This place has been very helpful so far.

I’ve just started learning Javascript, and the syntax keeps getting me. I’ve found an example of a javascript function that dynamically creates a div element, and I’ve tried to implement it in my code, but fault is found with it – but not by me. I do not know where the code is bad. Could someone point out what syntax (or worse) is wrong?

I call the function with

<body onload="creatediv()">

Here is the javascript function:

function creatediv(){

    for (i=1;i<13;i++){
        var newcovdiv = document.createElement('div');
        newcovdiv.setAttribute('id',"cover_"+i);
        newcovdiv.style.width=900;
        newcovdiv.style.height=25;
        newcovdiv.style.position="relative";
        newcovdiv.style.left=0;
        newcovdiv.style.top=(i-1)*25;
        newcovdiv.style.background="#FFFFFF";
        newcovdiv.style.display="none";
        document.getElementById('staff').appendChild(newcovdiv);
    }

    var newstaffdiv = document.createElement('div');
    newstaffdiv.setAttribute('id',"staff_sub");
    newstaffdiv.style.width=900;
    newstaffdiv.style.height=300;
    newstaffdiv.style.position="relative";
    newstaffdiv.style.left=0;
    newstaffdiv.style.top=0;
    newstaffdiv.style.background-image="url(../images/staff_sub.png);
    newstaffdiv.style.display="none";
    document.getElementbyId('staff').appendChild(newstaffdiv);

    for (i=13;i<101;i++){
        var newcovrdiv = document.createElement('div');
        newcovrdiv.setAttribute('id',"cover_"+i);
        newcovrdiv.style.width=900;
        newcovrdiv.style.height=25;
        newcovrdiv.style.position="relative";
        newcovrdiv.style.left=0;
        newcovrdiv.style.top=(i-1)*25;
        newcovrdiv.style.background="#FFFFFF";
        newcovrdiv.style.display="none";
        document.getElementById('paper').appendChild(newcovrdiv);
    }

}

There are already divs with the ids “paper” and “staff”. This is my first time using the appendChild thingy, so I thought the problem might be there.

This is bothersome. I will be grateful to anyone who tries to lend me a hand.

Thanks much.

  • 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-09T18:04:16+00:00Added an answer on June 9, 2026 at 6:04 pm

    There are a few obvious problems with your code:

    1) You can’t use background-image, because property names can’t be hyphenated when using the dot form, also it’s missing a “.

    style.backgroundImage
    

    2) All of the numeric type properties (top, left, width, height) are supposed to be css strings, so they all need to be converted to

    style.width = '900px'
    

    3) Your onload function calls creatediv(), however the function you posted is called letsgetiton, not sure if that’s just because of the way you posted it or how it is in your actual code.

    4) document.getElement*B*yId
    Case matters

    You might want to look at the Chrome developer tools or firebug in firefox. That error would have popped up straight away.

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

Sidebar

Related Questions

EDIT - The code looks strange here, so I suggest viewing the files directly
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: See my answer below--> I am wanting to have a view that when
EDIT : It turned out that this can only be done through an external
I'll preface this with the fact that I'm new to RoR. I have a
Edit: Two options shown below. If you're just using the functionality that an IDisposable
OLD QUESTION, SEE BELOW FOR THE UPDATED VERSION My development environment is not the
My concern in the code below is that the param to constructor is not
EDIT 2 : I have solved the problem (see answer below) Please note that
EDIT: Apparently I was a little confusing. The original post will remain below, but

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.