There is a simple code:
<div id="r">0</div> <button id="b" onclick="inc()"></button> <script> function my_click(){ document.getElementById("b").click(); } my_click(); function inc(){ var val = parseInt(document.getElementById("r").innerHTML); val++; document.getElementById("r").innerHTML = String(val); my_click(); } </script> But, for some strange reason, inc () only works once. That is, in the diva appears 1, and no more. What am I missing?
inc()works only when a button is pressed, increases by 1valand then callsmy_click(). As a result, with a single click on the button, the val increases by 2, right? - Aliaksandr Pitkevich