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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:03:29+00:00 2026-05-30T20:03:29+00:00

I want to do DRAG and REPLACE div in javascript. For Ex: I am

  • 0

I want to do DRAG and REPLACE div in javascript. For Ex: I am having 2 Div’s. If i drag the 2nd Div and place it on the 1st Div, automatically the 1st div should be replaced to the 2nd position. The code which i am having now is overlapping..

my aspx page..

<body>
<div id="container">
    <div id="info">
        Start drag process...</div>
    <div id="square" style="position: relative; width: 60px; height: 60px; background: #990033;
        border: 2px solid #3399CC;">
    </div>
      <div id="Div1" style="position: relative; width: 60px; height: 60px; background: #efe;
        border: 2px solid #3399CC;">
    </div>
    <script type="text/javascript">

        var square = DragHandler.attach(document.getElementById('square'));

        var Div1 = DragHandler.attach(document.getElementById('Div1'));


    </script>
</div>

my js file…

/**

*
* Crossbrowser Drag Handler
* http://www.webtoolkit.info/
*
**/

var DragHandler = {

// private property.
_oElem : null,


// public method. Attach drag handler to an element.
attach : function(oElem) {
    oElem.onmousedown = DragHandler._dragBegin;

    // callbacks
    oElem.dragBegin = new Function();
    oElem.drag = new Function();
    oElem.dragEnd = new Function();

    return oElem;
},


// private method. Begin drag process.
_dragBegin : function(e) {
    var oElem = DragHandler._oElem = this;

    if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
    if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }

    var x = parseInt(oElem.style.left);
    var y = parseInt(oElem.style.top);

    e = e ? e : window.event;
    oElem.mouseX = e.clientX;
    oElem.mouseY = e.clientY;

    oElem.dragBegin(oElem, x, y);

    document.onmousemove = DragHandler._drag;
    document.onmouseup = DragHandler._dragEnd;
    return false;
},


// private method. Drag (move) element.
_drag : function(e) {
    var oElem = DragHandler._oElem;

    var x = parseInt(oElem.style.left);
    var y = parseInt(oElem.style.top);

    e = e ? e : window.event;
    oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
    oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';

    oElem.mouseX = e.clientX;
    oElem.mouseY = e.clientY;

    oElem.drag(oElem, x, y);

    return false;
},


// private method. Stop drag process.
_dragEnd : function() {
    var oElem = DragHandler._oElem;

    var x = parseInt(oElem.style.left);
    var y = parseInt(oElem.style.top);

    oElem.dragEnd(oElem, x, y);

    document.onmousemove = null;
    document.onmouseup = null;
    DragHandler._oElem = null;
}

}

How to do this…

  • 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-30T20:03:30+00:00Added an answer on May 30, 2026 at 8:03 pm

    Here is the recognition part:

    for (var i = 0; i < document.getElementsByClassName("draggable").length; i++) {
        var elem = document.getElementsByClassName("draggable")[i];
    
        if (elem != oElem) {
    
            if (oElem.offsetTop + parseInt(oElem.style.height) > elem.offsetTop
               && oElem.offsetTop < elem.offsetTop + parseInt(elem.style.height)) {
                if (oElem.offsetLeft + parseInt(oElem.style.width) > elem.offsetLeft
                   && oElem.offsetLeft < elem.offsetLeft + parseInt(elem.style.width)) {
                    alert("overlapping");
                }
            }
        }
    }
    

    Your div’s need to have a “draggable” class.
    Demo: http://jsfiddle.net/DqJrV/

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

Sidebar

Related Questions

i have a div i want to drag confined in a particular container. i
I want to be able to drag and drag App model which is nested
i want to drag and drop my UIButton from one place to another, and
want to drag element to specific div and if not dragged to this div
I want to drag a div of left panel and drop it to right
I am doing an android app, I want to drag an image and place
I have an image-based map. I want to drag a div within a specified
I have a very simple application test in which I want to drag and
I want to drag and drop an image on wpf application form. Can anyone
I'm testing the ogl package in wxpython. I want to drag a shape. And

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.