Is it possible to append a child back to a position within a <td>
element in a table. I have 4 basketballs and when one is dragged to a net after a period of about 800 milliseconds I want to return it to it original position. I can remove the child node (the selected basketball) and I can return it to the table after a time.
The HTML code:
<td id="tdId1" style="width:60px;"><div id="bball1" onclick="ballSelection(this.id)"></div></td>
<td id="tdId2" style="width:60px;"><div id="bball2" onclick="ballSelection(this.id)"></div></td>
<td id="tdId3" style="width:60px;"><div id="bball3" onclick="ballSelection(this.id)"></div></td>
<td id="tdId4" style="width:60px;"><div id="bball4" onclick="ballSelection(this.id)"></div></td>
The problem is that when I remove it and then append it, It appends to the end of the row <tr>
element and not the <td>
. It always append to the last position.
Can it be appended to its original place. For example second in the row?
The JavaScript code:
var node = document.getElementById(this.Id);
if (node.parentNode) {
node.parentNode.removeChild(node);
var node2 = document.getElementById("tdId2");
setTimeout(function() {node2.parentNode.appendChild(node); }, 800);
}
I have tried to append to the second just as a starting point.
Any help appreciated.