I'm running a SetInterval in an HTML element in order to do a countdown. Here's the problem:
if (hours1 > 0) {
if (hours1 === 1) {
document.getElementById("hours1").textContent = hours1 + ":Hour ";
} else {
document.getElementById("hours1").textContent = hours1 + ":Hours ";
}
} }
I load up the HTML via AJAX at start of layout. If, I go to a different layout, the interval keeps running but it's no longer able to find the textContent (obviously) and floods the console with errors.
Ultimately, I'd like for the interval to keep running so that I don't have to do ajax calls each time the layout is loaded and can do them only when needed. Any way around this?
Thx