File tree Expand file tree Collapse file tree 3 files changed +113
-0
lines changed
44. Interchangeable Background Color Expand file tree Collapse file tree 3 files changed +113
-0
lines changed Original file line number Diff line number Diff line change 1+ const btns = document . querySelectorAll ( ".btn" ) ;
2+
3+ btns . forEach ( ( btn ) => {
4+ btn . addEventListener ( "click" , ( ) => {
5+ number = btn . value ;
6+ changeBackground ( number ) ;
7+ } ) ;
8+ } ) ;
9+
10+ const body = document . body ;
11+
12+ function changeBackground ( number ) {
13+ body . className = "" ;
14+ switch ( number ) {
15+ case "purple" :
16+ body . classList . add ( "purple" ) ;
17+ break ;
18+ case "blue" :
19+ body . classList . add ( "blue" ) ;
20+ break ;
21+ case "red" :
22+ body . classList . add ( "red" ) ;
23+ break ;
24+ case "green" :
25+ body . classList . add ( "green" ) ;
26+ break ;
27+ case "yellow" :
28+ body . classList . add ( "yellow" ) ;
29+ break ;
30+ case "teal" :
31+ body . classList . add ( "teal" ) ;
32+ break ;
33+ default :
34+ break ;
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ < html lang ="en ">
2+ < head >
3+ < meta charset ="UTF-8 " />
4+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Interchangeable Background Color</ title >
7+ < link rel ="stylesheet " href ="style.css " />
8+ </ head >
9+ < body >
10+ < div class ="content-container ">
11+ < nav class ="nav ">
12+ < input type ="button " value ="purple " class ="btn purple " />
13+ < input type ="button " value ="blue " class ="btn blue " />
14+ < input type ="button " value ="red " class ="btn red " />
15+ < input type ="button " value ="green " class ="btn green " />
16+ < input type ="button " value ="yellow " class ="btn yellow " />
17+ < input type ="button " value ="teal " class ="btn teal " />
18+ </ nav >
19+ </ div >
20+
21+ < script src ="app.js "> </ script >
22+ </ body >
23+ </ html >
Original file line number Diff line number Diff line change 1+ * {
2+ margin : 0 ;
3+ padding : 0 ;
4+ box-sizing : border-box;
5+ }
6+
7+ body {
8+ background : rgb (28 , 28 , 35 );
9+ }
10+
11+ .content-container {
12+ height : 100vh ;
13+ display : flex;
14+ flex-direction : column;
15+ justify-content : center;
16+ align-items : center;
17+ }
18+
19+ .btn {
20+ padding : 10px 20px ;
21+ border : none;
22+ color : # fff ;
23+ border : 2px solid white;
24+ width : 120px ;
25+ height : 100px ;
26+ margin : 20px ;
27+ cursor : pointer;
28+ font-weight : bold;
29+ text-transform : uppercase;
30+ }
31+
32+ .purple {
33+ background-color : purple;
34+ }
35+
36+ .blue {
37+ background-color : blue;
38+ }
39+
40+ .red {
41+ background-color : red;
42+ }
43+
44+ .green {
45+ background-color : green;
46+ }
47+
48+ .yellow {
49+ background-color : yellow;
50+ }
51+
52+ .teal {
53+ background-color : teal;
54+ }
You can’t perform that action at this time.
0 commit comments