I suggest an adjustment to the function where you create the clones. Something like this:
function mousedown(e) {
e.preventDefault();
var evt = e || window.event;
var el = ddData.element = evt.target || evt.srcElement;
var id = ddData.element.id
if (!el || el.tagName == 'svg' || ddData.movidos[id]) return ddData.element = null;
var clone = el.cloneNode(true);
el.id = id + '_' + (ddData.contadorElementos++);
el.parentNode.appendChild(clone);
In this way each new clone will have the original ID, and the element that drags ( ddData.element
) will have a unique ID formed by the ID of the original element ( img1
or img2
in the example you have) plus one part _x
which is the number of ddData.contadorElementos
that is always increasing each element generated.
In this way you always have unique IDs and you can go get the element when you need it and whose ID is registered in the keys of your ddData.movidos
object.