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

  • Home
  • SEARCH
  • 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 7433719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:43:00+00:00 2026-05-29T09:43:00+00:00

I am trying to note the position of a draggable div relative to its

  • 0

I am trying to note the position of a draggable div relative to its DOM parent. I have a global object g that contains another object bPos which is supposed to contain the position of div class = 'b' within div id ^= 'd'.

This is my code:

function() {
        var thisDiv = "";
        var thisDivID = "";
        $(".b").draggable({
            start: function(event, ui) {
                thisDiv = $(this).closest("div[id^='d']");
                thisDivID = thisDiv.attr("id");
                console.log(thisDivID); //also returning undefined

            },
            stop: function(event, ui) {
                var thisX = event.pageX;
                var thisY = event.pageY;
                var thisbPos = {
                    id: thisDivID,
                    x: thisX,
                    y: thisY
                }
                g.bPos[thisDivID] = thisbPos;
                console.log(thisDivID);// returning undefined
            }
        });
}

The console shows that thisDivID is undefined. Even if I assign an arbitrary value to it, it still comes up as undefined. Any help would be great.

  • 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-29T09:43:01+00:00Added an answer on May 29, 2026 at 9:43 am

    Use the ‘drag:’ method instead.
    I used this to allow list items to be dragged ‘out’ of the list with a little bit of resistance. Normally the y grid is set to a high number so it can’t move left and right, only up and down. In this code here, it’ll pop out and be free-moving after the user tries to move it to the left or right 127px.

    Hopefully you get the idea from this code I had lying around:

    drag: function (event, ui)
    {
        var left = ui.offset.left; //Offset of the list item currently being dragged
    
        if (parseInt(left) > 127)
        {
            if (!overlay)
            {
                overlay = true;
                $(".li-unreachable").draggable("option", "grid", [1, 1]); //free-moving
                showOverlay();
            }
        } else
        {
            if (overlay)
            {
                hideOverlay();
                $(".li-unreachable").draggable("option", "grid", [300, 50000]); //y-axis more or less locked down
                overlay = false;
            }
        }
    

    Edit: Let me know if you need some more code, I only grabbed the part that seemed relevant.

    Edit 2: Thought I should point out as well, your code should work if you change “$(this)” to “ui”.

    Edit 3: Here’s some code that’s more to the point:

    $(".b").draggable({
        start: function(event, ui) {
            var x = ui.offset.left; //x coordinate of the object that is being dragged.
            var y = ui.offset.top; //y coordinate of the object that is being dragged.
            var elementBeingDragged = ui.item; // ui.helper would work too.
        },
        stop: function(event, ui) {
            var x = ui.offset.left; //x coordinate of the object that is being dragged.
            var y = ui.offset.top; //y coordinate of the object that is being dragged.
            var elementBeingDragged = ui.item; // ui.helper would work too.
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a Tomboy note that has a link to another note
I'm trying to have some padding around the background image which is position to
I'm trying to create a <div> that has an opacity of 60%. I want
I'm trying to position two TextView's to the right of an image view (note
After trying every possible variation of position: relative/absolute/etc and negative margins, I'm wondering if
I'm trying to make two squares overlap eachother in a parent div. The squares
I'm trying to make a customized ListView, that should display a note title and
Im currently having trouble trying to understand linked lists. I have some code that
I have been trying to position content within a table row. The row in
I am trying to debug a strange issue with users that have LogMeIn installed.

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.