I am trying to make a chess game. So far i have only made the white pawns moveable (you move them by dragging them to where you want them to go). However, only the first move works. Why does this happen? I use
$(".piece").mousedown(function(){}
, but it is only called once.
The problem is
$("#" + tileFn).append($("#" + tileIn).html());
which creates a newpiece
element, to whom the mousedown handler is not attached.One solution is to use event deletagation, or instead of creating a new element just move the existing element like