Skip to content

Commit ea977e5

Browse files
committed
addWnetListener Example added
1 parent 78b6a33 commit ea977e5

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Simple Example of Event Listener</title>
8+
<style>
9+
* {
10+
box-sizing: border-box;
11+
}
12+
13+
#container{
14+
15+
16+
margin-top: 45vh;
17+
border: 2px red solid;
18+
display: flex ;
19+
flex-direction:column;
20+
gap: 20px;
21+
justify-content: space-around;
22+
padding: 20px;
23+
align-items: center;
24+
25+
}
26+
.btn_container{
27+
display: flex;
28+
justify-content: space-between;
29+
gap: 20px;
30+
align-items: center;
31+
}
32+
.btn_container :first-child{
33+
color: red;
34+
}
35+
.btn_container :nth-child(2){
36+
color: blue;
37+
}
38+
button{
39+
width: 50%;
40+
margin: auto;
41+
background-color: azure;
42+
border-radius: 10px;
43+
width: 100px;
44+
height: 50px;
45+
font-size: larger;
46+
}
47+
</style>
48+
</head>
49+
<body>
50+
<div id="container">
51+
<h1>Simple Example of Event Listener</h1>
52+
click the button to see the event listener in action:
53+
54+
<div class="btn_container">
55+
<button id="btn-red">Red!</button>
56+
57+
58+
<button id="btn-blue">Blue</button>
59+
</div>
60+
61+
</div>
62+
<script>
63+
// Select the button element
64+
const buttonRed= document.getElementById("btn-red");
65+
const buttonBlue=document.getElementById("btn-blue");
66+
const bg= document.getElementById("container");
67+
68+
// Add an event listener to the button
69+
buttonRed.addEventListener("click", function() {
70+
bg.style.backgroundColor = "red";
71+
});
72+
buttonBlue.addEventListener("click",function(){
73+
bg.style.backgroundColor="blue"
74+
})
75+
76+
77+
</script>
78+
</body>
79+
80+
81+
82+
83+
84+
85+
86+
</html>

0 commit comments

Comments
 (0)