File tree 1 file changed +32
-0
lines changed
1 file changed +32
-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 Interval</ title >
7
+ </ head >
8
+ < body >
9
+ < h1 > </ h1 >
10
+ < button id ="start "> Start</ button >
11
+ < button id ="stop "> Stop</ button >
12
+ </ body >
13
+ < script >
14
+ // Took a variable globally
15
+ let start ;
16
+
17
+ // Made a func. to update h1's inner text
18
+ function addText ( str ) {
19
+ document . querySelector ( 'h1' ) . innerHTML += str
20
+ }
21
+
22
+ // Added a addEventListener in which a setInterval to perform a task on every 1 sec
23
+ document . querySelector ( '#start' ) . addEventListener ( 'click' , function ( ) {
24
+ start = setInterval ( addText , 1000 , ' Run' ) // (' Run') parameter passed
25
+ } )
26
+
27
+ // Added a addEventListener to stop that interval
28
+ document . querySelector ( '#stop' ) . addEventListener ( 'click' , function ( ) {
29
+ clearInterval ( start )
30
+ } )
31
+ </ script >
32
+ </ html >
You can’t perform that action at this time.
0 commit comments