File tree 4 files changed +74
-0
lines changed
JavaScript/Advance/DOM/9. DOM Event Listener
4 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ h2 {
2
+ font-family : monospace;
3
+ }
4
+
5
+ div {
6
+ width : 300px ;
7
+ height : 300px ;
8
+ border : 1px solid black;
9
+ text-align : center;
10
+ }
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 http-equiv ="X-UA-Compatible " content ="IE=edge ">
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8
+ < title > DOM Event Listner</ title >
9
+ < link rel ="stylesheet " href ="css/style.css ">
10
+ < link src = "images/js-logo.png ">
11
+ </ head >
12
+
13
+ < body >
14
+ < h1 > DOM Event Listener</ h1 >
15
+ < h2 > Example One</ h2 >
16
+ < div id ="exampleOne ">
17
+ < h2 > OnClict Event</ h2 >
18
+ </ div >
19
+ < h2 > Example Two</ h2 >
20
+ < div id ="exampleTwo ">
21
+ < h2 > On Mouse Over</ h2 >
22
+ </ div >
23
+ < h2 > Example Three</ h2 >
24
+ < div id ="exampleThree ">
25
+ < h2 > On Mouse Out</ h2 >
26
+ </ div >
27
+ < script src ="script.js "> </ script >
28
+ </ body >
29
+
30
+ </ html >
Original file line number Diff line number Diff line change
1
+ // Example One
2
+ let exampleOne = document . getElementById ( 'exampleOne' ) ;
3
+
4
+ exampleOne . addEventListener ( "click" , ( ) => {
5
+ exampleOne . style . backgroundColor = "Green" ;
6
+ exampleOne . style . color = "white" ;
7
+ } ) ;
8
+
9
+
10
+ // Example Two
11
+ let exampleTwo = document . getElementById ( 'exampleTwo' ) ;
12
+
13
+ exampleTwo . addEventListener ( "mouseover" , ( ) => {
14
+ exampleTwo . style . backgroundColor = "Blue" ;
15
+ exampleTwo . style . color = "White" ;
16
+ } ) ;
17
+ exampleTwo . addEventListener ( "mouseout" , ( ) => {
18
+ exampleTwo . style . backgroundColor = "white" ;
19
+ exampleTwo . style . color = "Green"
20
+ } ) ;
21
+
22
+ // Example Three
23
+
24
+ let exampleThree = document . getElementById ( 'exampleThree' ) ;
25
+
26
+ exampleThree . addEventListener ( "mouseover" , ( ) => {
27
+ exampleThree . style . backgroundColor = "purple" ;
28
+ exampleThree . style . Color = "white" ;
29
+ } )
30
+
31
+ exampleThree . addEventListener ( "mouseout" , ( ) => {
32
+ exampleThree . style . backgroundColor = "white" ;
33
+ exampleThree . style . color = "purple" ;
34
+ } )
You can’t perform that action at this time.
0 commit comments