javascript - getting the id of something that has been dropped -
i want make drag & drop videoplayer , i'm stuck.
i have several div dropzones , want videos (div id/picture of video linked videofile) have been dropped, play 1 after another. im gonna array. problem can't dropzones tell me has been dropped them. i've tried several things nothing worked.
i'm using:
<div id="divdropzone1" ondrop="drop(event)" ondragover="allowdrop(event)"></div> <div id="video1" draggable="true" ondragstart="drag(event)"><img src="images/video1.jpg" onclick="video1()"></div> 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)); }
var data=ev.datatransfer.getdata("text");
that line of code key, if change drop()
following
function drop(ev){ ev.preventdefault(); var data=ev.datatransfer.getdata("text"); console.log(data); ev.target.appendchild(document.getelementbyid(data)); }
you see can id of element dropped.
Comments
Post a Comment