File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed
Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < title > DOM Manipulation</ title >
5+ < style >
6+ body {
7+ text-align : center;
8+ }
9+
10+ # my-button {
11+ height : 50px ;
12+ width : 50px ;
13+ font-size : 25px ;
14+ border : none;
15+ border-radius : 5px ;
16+ }
17+
18+ .odd {
19+ background-color : aqua;
20+ }
21+ .even {
22+ background-color : lawngreen;
23+ }
24+ </ style >
25+ </ head >
26+ < body >
27+ < h2 > Times of Button Pressed</ h2 >
28+ < button id ="my-button " onclick ="buttonPressed() "> </ button >
29+
30+ < script >
31+ //let noOfTimesClicked = 0;
32+
33+ let noOfTimesClicked = localStorage . getItem ( "noOfTimesClicked" ) || 0 ;
34+
35+ function buttonPressed ( ) {
36+ noOfTimesClicked ++ ;
37+
38+ localStorage . setItem ( "noOfTimesClicked" , noOfTimesClicked ) ;
39+
40+ updateButton ( ) ;
41+ }
42+
43+ function updateButton ( ) {
44+ let button = document . querySelector ( "#my-button" ) ;
45+
46+ if ( noOfTimesClicked % 2 === 0 ) {
47+ button . classList . add ( "even" ) ;
48+ button . classList . remove ( "odd" ) ;
49+ } else {
50+ button . classList . remove ( "even" ) ;
51+ button . classList . add ( "odd" ) ;
52+ }
53+
54+ button . innerText = noOfTimesClicked ;
55+ }
56+
57+ updateButton ( ) ;
58+ </ script >
59+ </ body >
60+ </ html >
You can’t perform that action at this time.
0 commit comments