How can I drag and replace the content when I drop; in this example: http://jsbin.com/uvihox/5/edit ?
function allowDrop(ev){
ev.preventDefault();
}
function drag(ev){
ev.dataTransfer.setData("Text",ev.target.id);
}
function drop(ev){
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
try this:
function drop(ev){
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
var s=document.getElementById(data);
ev.target.appendChild(s);
ev.target.src=s.src;
}
update your drop function like this. basically, you need to update the src of dropped img. It works for now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.