I have a code snippet that is intended to display a series of numbers to users. Ideally, it should show:
1
2
3
4
However, the current implementation only displays:
1
4
Here is the code I am using:
<script>
function myFunction() {
setTimeout(function() {
document.getElementById('p').innerHTML = "1";
}, 2000);
setTimeout(function() {
document.getElementById('p').innerHTML = "2";
}, 4000);
setTimeout(function() {
document.getElementById('p').innerHTML = "3";
}, 4000);
setTimeout(function() {
document.getElementById('p').innerHTML = "4";
}, 4000);
};
</script>
<p id="p"></p>
<input onclick="myFunction()" type="submit" />
Can someone help me understand why this issue is occurring?
Thank you in advance.