-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13.html
More file actions
78 lines (69 loc) · 1.88 KB
/
Copy path13.html
File metadata and controls
78 lines (69 loc) · 1.88 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.btn,
.all-btn{
background-color: aquamarine;
padding: 20px;
}
.p-btn{
background-color: rgb(231, 196, 240);
padding: 20px;
}
p{
background-color: yellowgreen;
}
</style>
</head>
<body>
<div>
<button class="btn">button</button>
<button class="all-btn">add</button>
</div>
<div class="product">
<button class="p-btn" data-id="apple">apple</button>
<button class="p-btn" data-id="orange">orange</button>
<button class="p-btn" data-id="banana">banana</button>
</div>
<div class="list"></div>
</body>
<script>
const p = document.querySelector('.product');
const c = document.querySelector('.list');
const btn = document.querySelector('.btn');
const allbtn = document.querySelector('.all-btn');
c.addEventListener('click',(e)=>{
console.log(e.target);
});
p.addEventListener('click', (e)=>{
const id = e.target.dataset.id;
if(id){
var p = document.createElement('p');
p.textContent = id;
p.className = 'product-item';
c.appendChild(p);
}
});
allbtn.addEventListener('click',()=>{
add();
});
btn.addEventListener('click',()=>{
console.log(c.childNodes);
while(c.childNodes){
c.removeChild(c.lastElementChild);
}
});
function add(){
for (var i = 0; i < 9; i++) {
var p = document.createElement('p');
p.textContent = '234';
c.appendChild(p);
}
}
</script>
</html>