javascript - JQuery click function not working after removing and adding back elements -
this click function
$('.cal table tbody td').on('click', function () { if($(this).hasclass('available')) { alert('asd'); } });
the problem having after have switched next or previous month, clicking function on calendar not work.
for example in jsfiddle, if u move previous month , move current month , click function, wouldn't work anymore.
edit: i'm using external library called date.js, check out jsfiddle clearer idea of going on.
edit 2: updated jsfiddle link
jsfiddle
use this
$(document).on('click','.cal table tbody td', function () { if ($(this).hasclass('available')) { alert('asd'); } });
instead of this
$('.cal table tbody td').on('click', function () { if ($(this).hasclass('available')) { alert('asd'); } });
former correct replacement delegate
Comments
Post a Comment