I am trying to append new element p into the div by every second, now I have something like this
<div id="div"> </div>
<button id="button" onclick="newfun()"> 1</button>
<script type="text/javascript">
function newfun() {
var d = new Date();
var t = d.getTime();
while(1) {
d = new Date();
var c = d.getTime();
if (c-t>1000) {
var para = document.createElement("p");
var node = document.createTextNode("new para");
para.appendChild(node);
var element = document.getElementById("div");
element.appendChild(para);
//return;
}
}
}
</script>
It just hangs there every time I click on the button. How should I change it to make it work?