The problem I have is with the jQuery datepicker. Execution of my function happens on the click of a certain date. The problem occurs when the month changes, then the entire datepicker is deleted from the DOM and a new datepicker appears.
My solution (bad solution) is with a constant wait for the arrow to change DOM, when that happens then I start further execution of the script. The biggest problem I have is performance, because I use interval.
This is my example of a solution that works, but barely...
$('#input-for-opening-datepicker').on('click', function(){
// In my attempt to solve the problem it is necessary to use an interval
// because without it the program does not see the change of the month
// and does not catch a click on the date.
setInterval( function(){
const arrows = $('.datepick-arrows');
// If arrows exist in DOM, wait for the click
if (arrows.length > 0){
arrows.on('click', function(){
// ... then wait for the date click to continue executing the code
$('.datepick-month table tbody tr td a').on('click', function() {
// Code...
});
});
// If you do not click on the change of the month, and the date picker
// is open then wait again for the click of a certain date because the
// change of the month does not have to happen by the user.
$('.datepick-month table tbody tr td a').on('click', function() {
// Code...
});
}
}, 200);
});
How do I achieve script execution without using an interval that greatly affects performance?
