This demo preserves the original Click to Start behavior. The callback is now a function rather than the legacy string 'disp()', and repeated clicks do not create overlapping intervals.
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>setInterval Demo</title></head>
<body>
<button type="button" id="startBtn">Click to Start</button>
<div id="n1"></div>
<script>
let timerId = null;
const output = document.getElementById("n1");
document.getElementById("startBtn").addEventListener("click", () => {
if (timerId !== null) return;
timerId = window.setInterval(() => {
output.append(document.createTextNode(" plus2net.com "));
}, 1000);
});
</script>
</body>
</html>
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.