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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:32:43+00:00 2026-06-03T20:32:43+00:00

I am making a sticky note system , and I want the sticky notes

  • 0

I am making a sticky note system, and I want the sticky notes to be draggable with javascript. I found a drag and drop script on this site which was quite useful to me. But I have a “drag bar” that is inside the sticky note div which is supposed to be the only place where you can drag that specific sticky note. The script I have drags only what the cursor is clicking on and I want it to drag the “.dragbar” div’s parent element, “.parent”.

Right now, the script is set to drag .parent when you click on .parent. How, in this code can I select the parent div of “.dragbar”, which is “.parent”?

If I make the script select .dragbar, it just moves the dragbar around inside the .parent. note: the script is the original code, except the selector names in lines 87 and 95 are changed from “drag” to “parent”.

<!DOCTYPE html>
<html>

    <head>
        <style type="text/css">
            .pagecontent {
                width:98%;
                height:96%;
                overflow:hidden;
                background:lightyellow;
                border:1px solid black;
                padding:10px;
            }
            .parent {
                position:relative;
                height:300px;
                width:300px;
                background-color:gray;
                border:1px solid black;
                float:left;
                margin:0 10px 0 0;
                overflow:auto;
            }
            .dragbar {
                height:50px;
                width:300px;
                background:lightgray;
                cursor:move;
                position:relative;
            }
        </style>
    </head>

    <body>
        <div class="pagecontent">
            <h1>Dragging Practice</h1>
            <h3>Drag and drop the parent div by using the child dragbar</h3>
            <pre id="debug">mouse up</pre>
            <div class="parent">
                <div class="dragbar">I am the Child, my class is .dragbar</div>I am the Parent, my class is
                .parent</div>
            <div class="parent">
                <div class="dragbar">I am the Child, my class is .dragbar</div>I am the Parent, my class is
                .parent</div>
            <script language="JavaScript" type="text/javascript">
                <!--
                // this is simply a shortcut for the eyes and fingers
                function $(id) {
                    return document.getElementById(id);
                }
                var _startX = 0; // mouse starting positions
                var _startY = 0;
                var _offsetX = 0; // current element offset
                var _offsetY = 0;
                var _dragElement; // needs to be passed from OnMouseDown to OnMouseMove
                var _oldZIndex = 0; // we temporarily increase the z-index during drag
                var _debug = $('debug'); // makes life easier
                InitDragDrop();

                function InitDragDrop() {
                    document.onmousedown = OnMouseDown;
                    document.onmouseup = OnMouseUp;
                }

                function OnMouseDown(e) {
                    // IE is retarded and doesn't pass the event object
                    if (e == null) e = window.event;
                    // IE uses srcElement, others use target
                    var target = e.target != null ? e.target : e.srcElement;
                    _debug.innerHTML = target.className == 'parent' //Selector
                    ?
                    'draggable element clicked' : 'NON-draggable element clicked';
                    // for IE, left click == 1
                    // for Firefox, left click == 0
                    if ((e.button == 1 && window.event != null || e.button == 0) && target.className == 'parent') //Selector
                    {
                        // grab the mouse position
                        _startX = e.clientX;
                        _startY = e.clientY;
                        // grab the clicked element's position
                        _offsetX = ExtractNumber(target.style.left);
                        _offsetY = ExtractNumber(target.style.top);
                        // bring the clicked element to the front while it is being dragged
                        _oldZIndex = target.style.zIndex;
                        target.style.zIndex = 10000;
                        // we need to access the element in OnMouseMove
                        _dragElement = target;
                        // tell our code to start moving the element with the mouse
                        document.onmousemove = OnMouseMove;
                        // cancel out any text selections
                        document.body.focus();
                        // prevent text selection in IE
                        document.onselectstart = function () {
                            return false;
                        };
                        // prevent IE from trying to drag an image
                        target.ondragstart = function () {
                            return false;
                        };
                        // prevent text selection (except IE)
                        return false;
                    }
                }

                function ExtractNumber(value) {
                    var n = parseInt(value);
                    return n == null || isNaN(n) ? 0 : n;
                }

                function OnMouseMove(e) {
                    if (e == null) var e = window.event;
                    // this is the actual "drag code"
                    _dragElement.style.left = (_offsetX + e.clientX - _startX) + 'px';
                    _dragElement.style.top = (_offsetY + e.clientY - _startY) + 'px';
                    _debug.innerHTML = '(' + _dragElement.style.left + ', ' + _dragElement.style.top + ')';
                }

                function OnMouseUp(e) {
                    if (_dragElement != null) {
                        _dragElement.style.zIndex = _oldZIndex;
                        // we're done with these events until the next OnMouseDown
                        document.onmousemove = null;
                        document.onselectstart = null;
                        _dragElement.ondragstart = null;
                        // this is how we know we're not dragging
                        _dragElement = null;
                        _debug.innerHTML = 'mouse up';
                    }
                }
                //-->
            </script>
        </div>
    </body>

</html>
  • 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-03T20:32:44+00:00Added an answer on June 3, 2026 at 8:32 pm

    I would advise you look into jQuery UI’s draggable and droppable. These will undoubtedly be more powerful than the script you linked, and you can set up elements to be draggable with jQuery’s powerful selectors, and droppable only within certain elements.

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

Sidebar

Related Questions

Making an adobe flex ui in which data that is calculated must use proprietary
Making my first steps in RIA Services (VS2010Beta2) and i encountered this problem: created
Making a drop down list for my JSP and the values I'm entering won't
Can you please go to: http://www.binarymark.com/Products/ColorPickerPro/default.aspx and note the page's layout. What I want
I'm making a site to document browser bugs where users can submit a bug
I am making 2D sprite engine in OpenGL and I want to disable mipmaps,
I'm having a little bit of trouble making a sticky form that will remember
I'm making finishing touches on my site and am struggling to make the load
I am making a voting system. When user click on a link with class
We are making a lab instrument using an ARM9/RTOS system. The client has asked

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.