vendredi 8 juillet 2016

setTimeout is working only once. Why? [duplicate]

This question already has an answer here:

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title></title>    
        <script>
         function move(){
  var i =10;
  var demo = document.getElementById('demo3');
  demo.innerHTML = i;

  function run(){
    demo.innerHTML = ++i ;
  }
  var id = setTimeout(run,1000);
}

        </script>
      </head>
      <body>
         <div class="main-content">
             <div class="micro"><p id="demo3"></p></div>
             <input type="button" class="btn" id="start" onclick="move()" name="name" value="Start">
         </div>
      </body>
    </html>

My code is not work properly. It should increase value of i continuously but it stops only after once. Please help.

Aucun commentaire:

Enregistrer un commentaire