-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.js
More file actions
60 lines (46 loc) · 1.36 KB
/
events.js
File metadata and controls
60 lines (46 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//Topic Event : Event handling in JS
//1.using simple functions
function display(){
console.log("Function get execute...");
}
//2. using addEventListner() method
document.getElementById("heading").addEventListener("click", function() {
console.log(document.getElementById("heading").innerHTML);
});
document.getElementById("para").addEventListener("dblclick" , function (evt) {
console.log("event haddled...");
console.log(evt);
});
//3. using arrow functions new ways
let btn = document.querySelector("#btn");
btn.onclick = () =>{
console.log('button clicked thorugh js ');
}
let div = document.querySelector("#div1");
div.addEventListener("click",() => {
console.log("event 1");
})
div.addEventListener("click",() => {
console.log("event 2");
})
const handler3 = () => {
console.log("event 3");
}
div.addEventListener("click",handler3);
div.addEventListener("click",() => {
console.log("event 4");
})
div.removeEventListener("click" , handler3)
//Dark to light mode
let btn2 = document.getElementById("darkToLightSwitch");
let currMode = "light" //dark
btn2.addEventListener("click", () => {
if(currMode === "light"){
currMode = "dark";
document.body.style.backgroundColor = "#070F2B";
}else{
currMode = "light";
document.body.style.backgroundColor = "#fff";
}
console.log(currMode);
});