user3354230 user3354230 - 1 year ago 50
Javascript Question

How to drag image while still leaving original image there?

How can I duplicate the image and drag it while leaving original in same place?

function allowDrop(ev) {

function drag(ev) {

function drop(ev) {
var data = ev.dataTransfer.getData("Text");;

#div1 {
width: 350px;
height: 200px;
padding: 10px;
border: 1px solid black;
img {
height: 100px;
width: 100px;

<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<img id="drag1" src="" draggable="true" ondragstart="drag(event)">

Answer Source

i think you want this:

function drop(ev)
   var data=ev.dataTransfer.getData("Text");;

it is almost what you did, but you have to clone the image and add the clone not the original!