-
Notifications
You must be signed in to change notification settings - Fork 4
/
Day 08 - Buttons Container.js
57 lines (45 loc) Β· 1.04 KB
/
Day 08 - Buttons Container.js
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
CSS:
.btnClass {
width: 96px;
height: 48px;
font-size: 24px;
}
JS:
var btn = document.createElement("Button");
btn.innerHTML = "0";
btn.id = "btn";
btn.className = "btnClass";
document.body.appendChild(btn);
btn.onclick = function() {
btn.innerHTML+=2;
}
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Button</title>
<link rel="stylesheet" href="css/button.css" type="text/css">
<style>
.button {
width: 96px;
height: 48px;
font-size: 24px;
}
</style>
</head>
<body>
<script>
var clickBtn = document.createElement('button');
let counter = 0;
clickBtn.innerHTML = counter;
clickBtn.id = 'btn';
clickBtn.className = 'button';
document.body.appendChild(clickBtn);
clickBtn.onclick = function () {
counter++;
btn.innerHTML = counter.toString();
};
</script>
</body>
</html>