File tree 1 file changed +28
-0
lines changed 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
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 >
You can’t perform that action at this time.
0 commit comments