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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:54:51+00:00 2026-06-18T09:54:51+00:00

EDIT : Here’s another problem: I can’t define each picture’s Z-index with the for

  • 0

EDIT : Here’s another problem: I can’t define each picture’s Z-index with the for loop.

function placeImage(x) {
    var div = document.getElementById("div_picture_right");

    div.innerHTML = ""; // clear images

    for (counter = 1; counter <= x; counter++ ) {
        var image = document.createElement("img");
        image.src = "borboleta/Borboleta" + counter + ".png";
        image.width = "195";
        image.height = "390";
        image.alt = "borboleta" + counter;
        image.id = "imagem" + counter;
        image.position = "relative";
        image.style.zIndex = counter;
        div.appendChild(image);
    }
};

window.onload = function () {
    placeImage(20);
};

<body>
    <div id="div_wrapper">
        <div id="div_header">
            <h1>First Project</h1>
        </div>
        <div id="div_picture">
            <div id="div_picture_left"></div>
            <div id="div_picture_right"></div>
        </div>
    </div>
</body>

When checking FireBug, I get this:

Error: image corrupt or truncated

  • 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-18T09:54:52+00:00Added an answer on June 18, 2026 at 9:54 am

    Looks like your code is executing before the div exists on the page. You shouldn’t try to get a handle on an element in the DOM until it is fully loaded. You can define your function outside of window.onload, but keep your call within window.onload, example:

    function placeImage(x)
    {
        var div = document.getElementById("div_picture_right");
    
        div.innerHTML = ""; // clear images
    
        for (counter=1;counter<=x;counter++) {
            var imagem=document.createElement("img");
            imagem.src="borboleta/Borboleta"+counter+".png";
            div.appendChild(imagem);
        }
    }
    
    window.onload = function() {
        placeImage(48);
    };
    

    I also added a small improvement which is to get the handle on the div and store in a variable once, instead of getting a new handle on each iteration.

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

Sidebar

Related Questions

EDIT Sorry I forgot the most important part here. Each key can have more
Edit- here's the code <html> <head> <script type=text/javascript> var prodURL = https://blah; function postwith
Edit: You can get the full source here: http://pastebin.com/m26693 Edit again: I added some
Edit: Here is the new code: $(#normalcontent).hide(fast).load($this.attr(href) + #normalcontent,,function(){ $(this).slideDown(normal); $(this).find(img).each(function(){ if($(this).hasClass(large)) { var
In my DataGrid, each row contains a RichTextBox. EDIT : Here is how the
http://jsbin.com/uxepap/3/edit Here is div with links inside. I'm trying to replace comma inside last
EDIT Here is the problem I am trying to solve: I have a string
How can I expand the whole TreeView in Silverlight? EDIT: Here is the XAML
EDIT: Apparently, the problem is in the read function: I checked the data in
EDIT: Here's the video showing the problem: www.youtube.com/watch?v=5ZZsuMH5T9k I'm really stuck here :/ --

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.