I would suggest the following pure JavaScript solution
HTML:
<div id="space" contenteditable="true"> Hello <img width="300" class="contentImg" src='http://www.independent.co.uk/incoming/article9859555.ece/alternates/w620/Dr-Talyor.jpg'/> dude! </div>
CSS
#space { width: 500px; height: 500px; background-color: #000000; color: #ffffff; }
JavaScript:
var draggedImg; document.addEventListener("dragstart", function( event ) { // IE uses srcElement, others use target var targ = event.target ? event.target : event.srcElement; if (targ.className == 'contentImg'){ draggedImg = event.target; } }, false); document.addEventListener("dragend", function( event ) { if(draggedImg){ alert("It moved!"); console.log('Here is data', draggedImg); draggedImg = null; } }, false);
You will find the node image in the draggedImg variable.
Check out a working example here: http://jsfiddle.net/o09hLtch/2/
source share