I have create a js file in which i am creating the dynamic table and dynamically changing the click event for the calendar but onclicking the calender image for dynamic gene
(2019) I used $('#'+id).removeAttr().off('click').on('click', function(){...});
I tried $('#'+id).off().on(...), but it wouldn't work to reset the onClick attribute every time it was called to be reset.
I use .on('click',function(){...}); to stay away from having to quote block all my javascript functions.
The O.P. could now use:
$(this).removeAttr('onclick').off('click').on('click', function(){
displayCalendar(document.prjectFrm[ia + 'dtSubDate'],'yyyy-mm-dd', this);
});
Where this came through for me is when my div was set with the onClick attribute set statically:
Otherwise, if I only had a dynamically attached a listener to it, I would have used the Without the off('click') my onClick listeners were being appended not replaced.$('#'+id).off().on('click', function(){...});.