-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.html
More file actions
82 lines (58 loc) · 2.2 KB
/
events.html
File metadata and controls
82 lines (58 loc) · 2.2 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
<title>Events</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<div class="container d-flex justify-content-center">
<div class="raw">
<div class="col">
<button onclick="alert('button 01 was cliked')" class="btn btn-primary">Button 01</button>
<button id="button2" class="btn btn-danger">Button 02</button>
<button id="button3" class="btn btn-warning">Button 03</button>
<button id="button4" class="btn btn-secondary">Button 04</button>
</div>
</div>
</div>
<script>
// Events
// ------
// Have Two type of Events in javascript
// we called that listlen to Events
// 01. using HTML Elements
// ex - <a onclick="doSomething()"> </a>
// 02. using addEventListener("event", function());
// element.addEventsListener("click", doSomething());
// Example events :
// * - click
// * - mouseover
// * - keyup
// * - keydown
// * - change
// background keyboard detect
document.addEventListener("keyup", function (event) {
console.log(event.keyCode, event.key);
})
// button 02
var mybtn2 = document.getElementById("button2");
mybtn2.addEventListener("click", doSomething);
function doSomething(event) {
console.log(event);
}
// button 03
var mybtn3 = document.getElementById("button3");
mybtn3.addEventListener("click", showButton3);
function showButton3() {
console.log("button 3 clicked");
}
// button 04
var mybtn4 = document.getElementById("button4");
mybtn4.addEventListener("click", showButton4);
function showButton4() {
console.log("button 4 clicked");
}
</script>
</body>
</html>