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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:43:54+00:00 2026-05-14T08:43:54+00:00

I have build a grid of div’s as playground for some visual experiments. In

  • 0

I have build a grid of div’s as playground for some visual experiments. In order to use that grid, i need to know the x and y coordinates of each div. That’s why i want to create a table with the X and Y position of each div.

X:0 & Y:0 = div:eq(0), X:0 Y:1 = div:eq(1), X:0 Y:2 = div:eq(2), X:0 Y:3 = div:eq(3), X:1 Y:0 = div:eq(4) etc..

What is the best way to do a table like that? Creating a OBJECT like this:

{
00: 0,
01: 1,
02: 2,
etc..
}

or is it better to create a array?

position[0][0] = 0

the thing is i need to use the table in multiple way’s.. for example the user clicked the div nb: 13 what are the coordinates of this div or what is the eq of the div x: 12 y: 5.

Thats how i do it right now:

        var row = 0
    var col = 0
    var eq = 0      

    c.find('div').each(function(i){ // c = $('div#stage')

        if (i !=0 && $(this).offset().top != $(this).prev().offset().top){
            row++
            col = 0
        }

        $(this).attr({'row': row, 'col': col })

        col++

    })

I think it would be faster to build a table with the coordinates, instead of adding them as attr or data to the DOM. but i cant figure out how to do this technically.

How would you solve this problem width JS / jQuery?

  • 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-14T08:43:55+00:00Added an answer on May 14, 2026 at 8:43 am

    A few questions:

    • Will the grid stay the same size or will it grow / shrink?
    • Will the divs stay in the same position or will they move around?
    • Will the divs be reused or will they be dynamically added / removed?

    If everything is static (fixed grid size, fixed div positions, no dynamic divs), I suggest building two indices to map divs to coordinates and coordinates to divs, something like (give each div an id according to its position, e.g. “x0y0”, “x0y1”):

    var gridwidth = 20, gridheight = 10,
        cells = [], // coordinates -> div
        pos = {}, // div -> coordinates
        id, i, j; // temp variables
    
    for (i = 0; i < gridwidth; i++) {
        cells[i] = [];
    
        for (j = 0; j < gridheight; j++) {
            id = 'x' + i + 'y' + j;
            cells[i][j] = $('#' + id);
            pos[id] = { x: i, y: j };
        }
    }
    

    Given a set of coordinates (x, y) you can get the corresponding div with:

    cells[x][y] // jQuery object of the div at (x, y)
    

    and given a div you can get its coordinates with:

    pos[div.attr('id')] // an object with x and y properties
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a grid[Grid1] that build its dataRows when a button[search] is clicked,
I need to have the currently selected row id in order to build a
I have to build a page which contains some text boxes and a grid
I have build C# program that work with RAPI (communication to PPC or WinCE)
I have a cube that I have build that has data across multiple servers.
For a client I have build a simple script that uploads multiple files(images), resizes
I'm trying to build a grid the size of the browser window that has
I have an Image control that contains a path to an embedded image (build
I have a view as <div class=main_content> <div class=form_container> <h1> Save Build Document Revision</h1>
I have to build a datagrid.The grid should be editable and values should be

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.