javascript - Check if event.target has Children -
<h1>this puzzle</h1> <h3>by julian blaschke </h3> <h4 id ="result">its wrong<h4> <table> <tr> <th>puzzle</th> </tr> <tr> <td><div id="dropdiv1" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> <td><div id="dropdiv2" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> <td><div id="dropdiv3" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> </tr> <tr> <td><div id="dropdiv4" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> <td><div id="dropdiv5" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> <td><div id="dropdiv6" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> </tr> <tr> <td><div id="dropdiv7" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> <td><div id="dropdiv8" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> <td><div id="dropdiv9" ondrop="drop(event)" ondragover="allowdrop(event)"></div></td> </tr> </table> <table style="width:100%"> <tr> <th>puzzle</th> </tr> <tr> <td><img id="1" src="splitted\1.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> <td><img id="2" src="splitted\2.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> <td><img id="3" src="splitted\3.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> <td><img id="4" src="splitted\4.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> <td><img id="5" src="splitted\5.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> <td><img id="6" src="splitted\6.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> <td><img id="7" src="splitted\7.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> <td><img id="8" src="splitted\8.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> <td><img id="9" src="splitted\9.png" draggable="true" ondragstart="drag(event)" width="100" height="80"></td> </tr> </table>
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"); if(ev.target.firstchild == null) ev.target.appendchild(document.getelementbyid(data)); } function checkifright(){ document.getelementbyid("result").innerhtml =(document.getelementbyid("dropdiv1").firstchild.src); if (document.getelementbyid("dropdiv1").firstchild.src == "file:///c:/users/julian/desktop/schule%20201617/bsd/html_javasccript/blaschke_puzzle/splitted/1.png") if (document.getelementbyid("dropdiv2").firstchild.src == "file:///c:/users/julian/desktop/schule%20201617/bsd/html_javasccript/blaschke_puzzle/splitted/2.png") document.getelementbyid("result").innerhtml ="right"; }
how can check in if statment if target has child.in if appends 2 times picture should added 1 time...
i don't undestand why. should work fine appends 2 times same picture 3 time not go in if statment
Comments
Post a Comment