File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 ">
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
+ < title > Dark Mode</ title >
8
+ < script defer src ="./DarkMode.js "> </ script >
9
+ < style >
10
+ * {
11
+ transition : 0.5s ease-out;
12
+ }
13
+
14
+ body {
15
+ background-color : white;
16
+ }
17
+
18
+ body .dark {
19
+ background-color : black;
20
+ color : white;
21
+ }
22
+
23
+ body .dark h1 {
24
+ color : plum;
25
+ }
26
+ </ style >
27
+ </ head >
28
+
29
+ < body class ="">
30
+ < button onclick ="modeChange() "> Mode</ button >
31
+ < h1 > This is heading.</ h1 >
32
+ </ body >
33
+
34
+ </ html >
Original file line number Diff line number Diff line change
1
+ const body = document . querySelector ( "body" )
2
+ // console.log(body)
3
+
4
+ const modeChange = ( ) => {
5
+ // if (!body.classList.contains("dark")) {
6
+ // body.classList.add("dark")
7
+ // } else {
8
+ // body.classList.remove("dark")
9
+ // }
10
+
11
+ body . classList . toggle ( "dark" ) // toggle function is like switch its functioning as the same as the above line
12
+ console . log ( body )
13
+ }
14
+
15
+
You can’t perform that action at this time.
0 commit comments