File tree Expand file tree Collapse file tree 3 files changed +99
-0
lines changed
Expand file tree Collapse file tree 3 files changed +99
-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 > Javascript Color Changer</ title >
7+ < link rel ="stylesheet " href ="style.css ">
8+ </ head >
9+ < body >
10+ < div id ="container ">
11+ < h2 id ="heading "> Background Color Changer</ h2 >
12+
13+ < button class ="button " id ="red "> </ button >
14+ < button class ="button " id ="green "> </ button >
15+ < button class ="button " id ="blue "> </ button >
16+ < button class ="button " id ="yellow "> </ button >
17+ < button class ="button " id ="black "> </ button >
18+
19+ < h3 id ="hint "> Click on above box to change background color</ h3 >
20+
21+ < button id ="reset "> Reset</ button >
22+ </ div >
23+
24+ < script src ="script.js "> </ script >
25+ </ body >
26+ </ html >
Original file line number Diff line number Diff line change 1+ const buttons = document . querySelectorAll ( 'button' ) ;
2+ const body = document . querySelector ( 'body' ) ;
3+
4+
5+ buttons . forEach ( function ( button ) {
6+ button . addEventListener ( 'click' , function ( e ) {
7+ if ( e . target . id === 'red' ) {
8+ body . style . backgroundColor = e . target . id ;
9+ }
10+ if ( e . target . id === 'green' ) {
11+ body . style . backgroundColor = e . target . id ;
12+ }
13+ if ( e . target . id === 'blue' ) {
14+ body . style . backgroundColor = e . target . id ;
15+ }
16+ if ( e . target . id === 'yellow' ) {
17+ body . style . backgroundColor = e . target . id ;
18+ }
19+ if ( e . target . id === 'black' ) {
20+ body . style . backgroundColor = e . target . id ;
21+ }
22+
23+ } ) ;
24+ } ) ;
25+
26+ const resetBtn = document . getElementById ( 'reset' ) ;
27+ resetBtn . addEventListener ( 'click' , function ( e ) {
28+ body . style . backgroundColor = "#23282D" ;
29+ } ) ;
30+
31+
32+
Original file line number Diff line number Diff line change 1+ body {
2+ display : flex;
3+ justify-content : center;
4+ background-color : # 23282D ;
5+ color : # fff ;
6+ }
7+ # container {
8+ margin-top : 20vh ;
9+
10+ }
11+ .button {
12+ height : 60px ;
13+ width : 60px ;
14+ }
15+ # red {
16+ background-color : red;
17+ }
18+ # green {
19+ background-color : green;
20+ }
21+ # blue {
22+ background-color : blue;
23+ }
24+ # yellow {
25+ background-color : yellow;
26+ }
27+ # black {
28+ background-color : black;
29+ }
30+ # heading {
31+ font-family : 'Segoe UI' , Tahoma, Verdana;
32+ font-size : 25px ;
33+ }
34+ # hint {
35+ font-size : medium;
36+ }
37+ # reset {
38+ height : 30px ;
39+ width : 90px ;
40+
41+ }
You can’t perform that action at this time.
0 commit comments