html - Javascript onDrop attribute not assigned -
i encountered wierd problem in javascript. tried create div box in drop other divs. strangely ondrop-attribute doesn't assigned div allthough if read it, seems have it. error here? here's fiddle
function creatleftrighttree(parentelement){ var lefttree = document.createelement("div"); var righttree = document.createelement("div"); lefttree.id="lefttree"; righttree.id="righttree"; lefttree.classname="dndcontainer"; righttree.classname="dndcontainer"; lefttree.ondrop="drop(event)"; righttree.ondrop="drop(event)"; righttree.ondragover="allowdrop(event)"; parentelement.appendchild(lefttree); parentelement.appendchild(righttree); righttree.innerhtml+= righttree.ondrop; //it must not possible drop in left tree } function drop(ev) { ev.preventdefault(); var data = ev.datatransfer.getdata("text"); var droptarget = ev.target; droptarget.appendchild(document.getelementbyid(data)); } function allowdrop(ev) { ev.preventdefault(); } function drag(ev) { ev.preventdefault(); } creatleftrighttree(document.getelementsbytagname("body")[0]);
edit: updated fiddle , code less confusion. wrote alternativ function called drop(event). doesn't matter though, cause problem is: doesn't change ondrop-attribute
javascript event handlers all-lowercase; mean ondrop
.
also, not assign strings; should assign function directly:
lefttree.ondrop = drop;
Comments
Post a Comment