-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.js
More file actions
42 lines (32 loc) · 1.02 KB
/
event.js
File metadata and controls
42 lines (32 loc) · 1.02 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
//events is the change in the state of an object
//they are fired to notify the interesting chnages
//ouse events,keyboard events,form events
let bt = document.querySelector("#btn");
bt.onclick = () => {
console.log("button was clicked");
}
//js handle is priortized over inline event
//event object;
bt.onclick = (e) => {
console.log(e);//prints event methods
console.log(e.type)
console.log(e.target)
console.log(e.clientX,e.clientY)
console.log("override");
}
let d = document.querySelector("div");
d.addEventListener("mouseover",()=>{
console.log("you clicked on div -1")
})//function is called after event is occured;
let handler = ()=>{
console.log("you clicked on div -2")
}
d.addEventListener("mouseover",handler)
d.addEventListener("mouseover",()=>{
console.log("you clicked on div -3")
})
d.addEventListener("mouseover",()=>{
console.log("you clicked on div -4")
})
//here function will be called 4 times and not overriiden;
d.removeEventListener("mouseover",handler) //handler fun is not called now