As I work on customizing a WordPress plugin called Spider Calendar, I've encountered an issue where the event listener disappears from the inspector's "event listeners" tab after clicking on certain elements like "2016", "2018", or the arrows. Despite this, the event listener still appears in the source code.
After conducting some research, my hunch is that this vanishing act might be due to the elements being destroyed. How can I ensure the event listener reloads each time the calendar is triggered? Alternatively, could there be another underlying cause that I'm missing?
Below is the snippet of my event listener code:
if (window.location.href.indexOf("bounce-houses/") > -1) {
var element = $('#afterbig1 table table table tr:nth-child(n+2) td');
element.click(function() {
if ($(this).is(":nth-last-child(2)") || $(this).is(":last-child") || $(this).is(":first-child")) {
$(this).toggleClass("selectedWeekend");
if ($(this).hasClass("calsun_days")) {
$(this).toggleClass("sundays");
$(this).toggleClass("calsun_days");
} else if ($(this).hasClass("sundays")) {
$(this).toggleClass("sundays");
$(this).toggleClass("calsun_days");
}
} else if ($(this).is('td:nth-child(n+2):nth-child(-n+5)')) {
$(this).toggleClass("selectedDays");
}
});
}
});
For reference, you can find the problematic page at the following link (please note that the calendar code is too extensive to include here):
johnabounceandplay.com/bounce-houses/combo-house