Skip to content

Commit 3273f10

Browse files
committed
Added a setTimeout method example code.
1 parent a9d20f5 commit 3273f10

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

08_Events/two.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Set Timeout</title>
7+
</head>
8+
<body>
9+
<h1>Ayush</h1>
10+
<button id="stop">Stop</button>
11+
</body>
12+
<script>
13+
// Made a func. to add some extra text to h1
14+
function addSurname() {
15+
document.querySelector('h1').innerHTML += " Yadav"
16+
console.log("Surname Added");
17+
}
18+
19+
// Added a setTimeout method to that func. to perform that task after 3 seconds
20+
const stopMe = setTimeout(addSurname, 3000)
21+
22+
// Added a addEventListener to stop that setTimeout method on clicking stop button
23+
document.querySelector('#stop').addEventListener('click', function(){
24+
clearTimeout(stopMe)
25+
console.log("Stopped");
26+
})
27+
</script>
28+
</html>

0 commit comments

Comments
 (0)