Decrements time in javascript
<p>(second.innerHTML) -1 that worked but (num.innerHTML) -1 that not working why? </p>

<pre><code>function doDcrements() {
     var hidden = document.getElementById('hidden');
     var second = document.getElementById('second');  // the second is 20.
     var loopTimer = 0;
     if (second.innerHTML != "0") {
         second.innerHTML = (second.innerHTML) -1;
         second.style.color = "blue";
         loopTimer = setTimeout('doDecrements()',1000);
     }else {
         second.style.color = "grey"; 
         hidden.style.display = "block";   
     }
 } 
</code></pre>

<p>.....................................................................................................................................................................</p>

<pre><code>function doDcrements() {
         var hidden = document.getElementById('hidden');
         var second = document.getElementById('second'); // the second is 20. 
         var loopTimer = 0; 
         var num = document.getElementById('num'); // the number is 20. 
         if (second.innerHTML != "0") {
             second.innerHTML = (num.innerHTML) -1;
             second.style.color = "blue";
             loopTimer = setTimeout('doDecrements()',1000);
         }else {
             second.style.color = "grey";  
             hidden.style.display = "block";   
         }
     } 
</code></pre>

<p>when I create it by for loop it not happens :</p>

<pre><code>function doDcrements() {
    var hidden = document.getElementById('hidden');
    var second = document.getElementById('second');
    for (i=20; i&lt;=0; i--) {
           if (second.innerHTML != "0") {
             second.innerHTML = i;
             second.style.color = "blue";
             loopTimer = setTimeout('doDecrements()',1000);
         }else {
             second.style.color = "grey";  
             hidden.style.display = "block";   
         }
    }
}
</code></pre>

<p>html code: </p>

<pre><code>&lt;div id="hidden"&gt;started&lt;/div&gt;
&lt;p id="second"&gt;20&lt;/p&gt;
&lt;div onClick="doDcrements();"&gt;Download&lt;/div&gt; 
</code></pre>
