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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:41:20+00:00 2026-06-16T21:41:20+00:00

EDIT: The Problem was in my code, I was not querying the array with

  • 0

EDIT: The Problem was in my code, I was not querying the array with the right index.
For anyone looking for an answer for this problem, Karthik Ar answered it right. Thanks for all the comments!

I´m struggling to create an array of unique canvas elements inside a for loop.
It seems as all elements were a copy of the first element created. Im saying this because I need to store this canvas in an array and then access their contexts anytime later.

    var _ctxs = new Array();
    function createCells()
            {
                _w = window.innerWidth;
                _h = window.innerHeight;
                var side = 300;
                //set amount of steps
                var stepsW = Math.ceil(_w/side) + 1;
                var stepsH = Math.ceil(_h/(side/2)) + 1;

                console.log("create cells");
                for (var i = 0; i < stepsH; i++) 
                {
                    var p = (i%2 == 0)?0:side/2;
                    for (var j = 0; j < stepsW; j++) 
                    {
                        var _tempCanvas = $('<canvas/>', {id: "i_" + i + "_" + j, width : side, height : side});
                        _tempCanvas.css({
                            'position' : 'absolute',
                            'top' : (i*(side/2)+1) - side/2,
                            'left' : (j*side + p) + 1 - side/2
                        });

                        //var _tempCtx = _tempCanvas[0].getContext('2d');
                        _ctxs.push(_tempCanvas[0]);

                        $('body').prepend(_tempCanvas);
                        k++;
                    };
                };
            }

Any Thoughs? Thanks in advance!

  • 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-16T21:41:21+00:00Added an answer on June 16, 2026 at 9:41 pm

    Looks working by your code check the array.

    $(document).ready(jqueryready);
    function jqueryready(){
    for (var i = 0; i < 5; i++) 
                {
    for (var j = 0; j < 5; j++) 
                    {
                        var _tempCanvas = $('<canvas/>', {id: i+""+j, width : 10, height : 10});
                        console.log(_tempCanvas[0].id);
                        $('body').prepend(_tempCanvas);
                    };
                    }
    }
    

    This creates unique id for canvas.

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

Sidebar

Related Questions

EDIT: PROBLEM SOLVED. It was the FitVids code causing the JWP to not display.
Ok, I'll put the code first hopefully to make it clearer. ***Edit: Problem is
[EDIT: Problem solved. Please see my answer below.] In my app I call the
Edit: This problem was down to me passing the wrong view to the Touch
[Edit: This problem applies only to 32-bit systems. If your computer, your OS and
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
EDIT: Problem solved. This was (yet another) situation where the problem wasn't really where
Not sure how to name correctly this question so feel free to edit if
I have a problem similar if not identical to the problem in this thread:
EDIT: Problem was due to a different part of my code. I thought it

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.