Newbie, using HTML, CSS, and Javascript. Currently working on a simple drag and drop practice page, and I believe I have the drag part down (i think) but I'm struggling because my ultimate goal is to have these two file icon images be able to drag and drop into a recycle bin image (as if i were sending them to an actual recycle bin), and both or either of the file icons disappear. It's not much and it's not pretty, but here's the code I have so far:
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTranfer.getData("text");
ev.target.appendChild(document.getElementById(data))
}
#trash {
width: 70px;
height: 70px;
border: 1px solid black;
}
<img id="trash" src="trash_can.png" "ondrop"=drop(event)" ondragover="allowDrop(event) ">
<br>
<img id="item1 " src="file_icon.png " draggable="true" ondragstart="drag(event) " width="70 " height="70 ">
<img id="item2 " src="file_icon.png " draggable="true" ondragstart="drag(event) " width="70 " height="70 ">