<div id="myDiv"></div> <button id="myButton">click</button> <script> window.onload = function () { var count = 0; myButton.onclick = function () { myDiv.innerHTML += '<div id="ac-' + count + '">div' + count + '</div>' count++; } } </script>