When making an Ajax call, I dynamically generate a div and create a click action associated with it. I give the div a unique ID based on a key value from the data. The problem arises when the same key value is received in subsequent Ajax calls.
var $orderData = $('<div><table width="100%"><tr><td nowrap width="15%">'+valX1
+ '</td><td width="10%" class="imgClass" ><img src='
+ imgPath + ' id="img_'+serId+'" /></td>
+ <td nowrap width="25%">' + customerName
+ '</td><td nowrap width="25%">' + orderPendingCount
+ '</td><td nowrap width="25%">'
+ plant+'</td></tr>' + '<tr><td nowrap width="15%">' + modelName
+ '</td><td></td><td nowrap width="25%">'
+ totalNo + '</td><td nowrap width="25%">'
+ deliveredTotal+'</td><td nowrap width="25%">'
+ salesPersonName + '</td></tr></table></div>' );
$('body').on('click', '#img_'+serId, function(){
$('body').css('cursor', 'default');
alert(serId);
return false;
});
The click action is triggered correctly, but problems arise when the same serId is used in multiple Ajax calls. The click action is created again for the div, resulting in repeated calls.
Is there a way to clear the div action script and div before creating it again?