SetInterval in HTMLElement

0 favourites
  • 1 posts
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)