-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_Events.js
More file actions
39 lines (27 loc) · 872 Bytes
/
Copy path10_Events.js
File metadata and controls
39 lines (27 loc) · 872 Bytes
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
// Events in JS :-
// The change in the state of an object is known as an Event
// Mouse events (click, double click etc.)
// Keyboard events (keypress, keyup, keydown)
// Form events (submit etc.)
// Print event & many more
node.event = ( ) => {
//handle here
}
const btn = document.getElementById("myBtn");
btn.onclick = ( ) => {
console.log("Button clicked!");
}
// Event Object :-
// It is a special object that has details about the event.
node.event = (e) => {
//handle here
}
// e.target, e.type, e.clientX, e.clientY, e.offsetX, e.offsetY
// Event Listeners :-
// node.addEventListener( event, callback )
// node.removeEventListener( event, callback )
// *Note : the callback reference should be same to remove the event
const button = document.getElementById("myButton");
button.addEventListener("click", function() {
alert("Button clicked!");
});