I want to use Javascript to add a text to a html element (such as the p tag) 15 times and it must wait one second every time it adds the text.
I tried some ways and didn't get the proper result. It adds all 15 texts after 15 seconds.
What should I do? Please help me.
var i = 0;
var element = document.getElementById("mydiv");
var interval = setInterval(function(){
if(i <= 14){
element.innerHTML += "sometext";
}else{
clearInterval(interval);
}
i++;
},1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With