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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:49:55+00:00 2026-05-30T10:49:55+00:00

I have the following html structure. Please read abcd and efgh in the ids

  • 0

I have the following html structure.
Please read “abcd” and “efgh” in the ids below as a random string that I generate and append it to give a unique id.

<div id="MainCanvas">
    <div id="canvas-1">
        <div id="MainDiv-abcd">
            <div id="Manvas-abcd">
            </div>
            <div id="Textdiv-abcd">
            </div>  
        </div>
        <div id="MainDiv-efgh">
            <div id="Manvas-efgh">
            </div>
            <div id="Textdiv-efgh">
            </div>  
        </div>
        ...there are more of the main Divs.
    </div>
    <div id="canvas-2">
    ....same structure as above.
    </div>    
</div>

My end goal is to iterate through all the spans and get some information regarding the spans.

My code right now is the following.

var counter = 1;
$('[id^="MainDiv-"]').each(function(i) {
        var spanId = this.id.replace("MainDiv-", "TextDiv-");
        if ($("#" + spanId).length) {
            if ($("#" + spanId).text().trim().length) {
                //here I get the canvas number which is a page in the application
                myPages[counter] = $(this).parent().attr("id").split("-")[1];
                //this is where I need to get the left and top position of the span
                //relative to the canvas
                counter = counter + 1;
            }
        }
    });

Open to changing the logic

  • 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-30T10:49:56+00:00Added an answer on May 30, 2026 at 10:49 am

    You could get the left and top offset of the parent and then subtract the left and top offset of the child you wish to get the position of.

    Something like this:

    var parent = $("#canvas"),
        child = $("#myspan"),
        parentTop = parent.offset().top,
        parentLeft = parent.offset().left,
        childTop = parent.offset().top,
        childLeft = parent.offset().left,
        childPosTop = parentTop - childTop,
        childPosLeft = parentLeft - childLeft;
    

    childPosTop should contain the child’s top offset relative to canvas and childPosLeft should contain its left offset relative to canvas.

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

Sidebar

Related Questions

Hey guys, I have the following HTML structure that I am trying to pull
I have a jQuery slideshow code that works fine with the following HTML structure:
I have following a HTML structure of list that contains another list: <ul> <li>a</li>
I have the following html structure (which is generated and I can't change): <table
I have the following HTML structure being returned from an AJAX request... <th scope=col
I have the following HTML structure: $('#subgroup a').nextUntil('h3').wrapAll('<div></div>'); <script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script> <div id=subgroup> <h3>Group name
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div
I have a necessity to sort a given HTML table of the following structure,
I have the following html.erb code that I'm looking to move to Haml: <span
I have the following html structure <div style=overflow-x:auto;overflow-y:hidden;position:relative> <div style=position:absolute; top:0;bottom:0;padding-top:30px> </div> </div> When

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.