title: Javascript onclick increment a number as text
body: <p>I have a problem with Javascript: I'm trying to increment a number which is a string, so I need to parse it, increment the value, and assign that number to the value in the field. But I don't understand why this code doesn't work properly:</p>
  
  <pre><code>&lt;button type="button" onclick="dec()" name="less" style="background-color: orange;border:none;"&gt;-&lt;/button&gt;
  &lt;script&gt;
    function dec() {
      var x = parseInt(document.getElementById("num").value, 10);
      x--;
      document.getElementById("num").value = x;
    }
  </code></pre>
  
  <p></p>
  
  <p>While the number is in a div like this:</p>
  
  <pre><code>&lt;div id="num" style="display:inline;"&gt;0&lt;/div&gt;
  </code></pre>
  
  <p>Where is the error?</p>