init();
function init(){
// If you can't recall the ids
// Check the previous post in this series
img = document.getElementById("img");
box1 = document.getElementById("left");
box2 = document.getElementById('right');
// The event that is called when you start dragging
img.addEventListener("dragstart", dragged);
// The event that is called when you finish dragging
box1.addEventListener("drop", dropped1);
box2.addEventListener("drop", dropped2);
// The events that are called when you enter the box
// and mouseover a box while dragging
box1.addEventListener("dragenter",function(e){e.preventDefault()});
box1.addEventListener("dragover",function(e){e.preventDefault()});
box2.addEventListener("dragenter",function(e){e.preventDefault()});
box2.addEventListener("dragover",function(e){e.preventDefault()});
}
function dragged(e){
var code = '<img id="img" width="100px" height="100px" src="http://lh4.googleusercontent.com/-A4PMZCZ_Fyg/AAAAAAAAAAI/AAAAAAAAB1w/XYEaZmdFVes/s512-c/photo.jpg">';
e.dataTransfer.setData('Text', code);
}
function dropped1(e){
e.preventDefault();
box1.innerHTML=e.dataTransfer.getData('Text');
box2.innerHTML='You can use this as the landing zone too!';
init();
}
function dropped2(e){
e.preventDefault();
box2.innerHTML=e.dataTransfer.getData('Text');
box1.innerHTML='This is the landing zone!';
init();
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.