JQuery click function not working after removing and adding back elements

calendar, css, html, javascript, jquery

Solution

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 is the correct replacement for `delegate`

Problem

this is my click function ``` $('.cal table tbody td').on('click', function () { if($(this).hasClass('available')) { alert('asd'); } }); ``` the problem i am having is that after i have switched to the next or previous month, my clicking function on the calendar does not work. For example in my JSFIDDLE, if u move to the previous month and then move back to the current month and do the click function, it wouldn't work anymore. EDIT: I'm using an external library called date.js, check out my jsfiddle for a clearer idea of what is going on. EDIT 2: updated jsfiddle link jsfiddle

Original source