Stop setinterval in innerhtml - Javascript DOM

Javascript examples for DOM:Element innerHTML

Description

Stop setinterval in innerhtml

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width"> 
   </head> 
   <body> 
      <div id="time"></div> 
      <script>
let time = 0;//from  w w  w .j  av a  2s.  com
let int = setInterval(() => {
  if(time === 10) 
     clearInterval(int);
  document.getElementById('time').innerHTML = 'seconds: ' + time;
  time++
}, 1000)

      </script>  
   </body>
</html>

Related Tutorials