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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:07:27+00:00 2026-06-16T14:07:27+00:00

OK complicated one – I have created some code to append a div within

  • 0

OK complicated one – I have created some code to append a div within a wrapper div:

$("#container").click(function(e){
   var parentOffset = $(this).parent().offset(); 
   var relX = e.pageX - parentOffset.left;
   var relY = e.pageY - parentOffset.top;

 $('#container').append('<div class="placeddiv" style="left:' + relX + '; top:' + relY +';"></div>');

This works ok if the placeddiv is set to position: absolute;

However, my container div is intentionally large (10,000px by 10,000px) and thus my wrapper div has overflow:scroll.

The issue is the placeddivs do not stay in the one position relative to the container. They only stay positioned relative to the wrapper.

I have tried using position:relative but then the placeddivs ‘stack’ on top of each other (ie you cannot add a 2nd placeddiv above the first).

Does anyone know a way around this?

(PS: I have tried to create a Fiddle http://jsfiddle.net/7WQ5Q/20/ but even though I have copied from my local verbatim (just changed names of divs to be more meaningful) it wont work. Never used JSFiddle before so I could be doing something wrong)

Any help is appreciated!

  • 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-16T14:07:28+00:00Added an answer on June 16, 2026 at 2:07 pm

    Couple of things:

    1. there was a JS typo
    2. you need to specify px if you’re going to set the position like that.
    3. your container needs to have position: relative
    4. you need to account for the scrolling yourself

    See this working fiddle forked from yours (updated with cleaner code):
    http://jsfiddle.net/wWEqP/5/

    $("#container").click(function(e){
        var wrapper = $(this).parent();
        var parentOffset = wrapper.offset(); 
        var relX = e.pageX - parentOffset.left + wrapper.scrollLeft();
        var relY = e.pageY - parentOffset.top + wrapper.scrollTop();
    
        $(this).append($('<div/>').addClass('placeddiv').css({
            left: relX,
            top: relY
        }));    
    });
    

    does that cover everything you were trying to accomplish?

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

Sidebar

Related Questions

I have one main view with an associated controller. I have some rather complicated
I have one complicated situation with JavaScript. I have created object. This object loads
I have a pair of static fields with a complicated one-time initialization. I want
I have one complicated question. I'll try to explain it with example: have one
I have a fairly complicated build workflow for one of my Jenkins builds. The
I have a complicated query I've been working on, and I recently changed one
I'm using Rails with the JQuery plugin, and have some really complicated validations for
OK here goes, This one i find complicated to explain, but I have attached
I have a fairly complicated NSTextView subclass in one of my projects. I'm currently
I have two complicated select statements, each of which returns one value of the

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.