No. | Title |
---|---|
1 | Code Example 1 Using setInterval |
2 | Code Example 2 Using setTimeout Recursively |
3 | Conclusion |
<!DOCTYPE html>
<html>
<head>
<title>Periodic Function Execution</title>
</head>
<body>
<p id="output">This text will be updated periodically.</p>
<script>
function updateText() {
const element = document.getElementById('output');
element.innerHTML = `Updated at ${new Date()}`;
}
// Call updateText function every 3 seconds (3000 milliseconds)
setInterval(updateText, 3000);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Periodic Function Execution</title>
</head>
<body>
<p id="output">This text will be updated periodically.</p>
<script>
function updateText() {
const element = document.getElementById('output');
element.innerHTML = `Updated at ${new Date()}`;
}
// Call updateText function every 3 seconds (3000 milliseconds)
setInterval(updateText, 3000);
</script>
</body>
</html>