-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice8-10.html
More file actions
31 lines (30 loc) · 936 Bytes
/
practice8-10.html
File metadata and controls
31 lines (30 loc) · 936 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=\, initial-scale=1.0">
<title>DOM 객체 동적 삽입</title>
<script>
function addAnswer(obj,text){
let div = document.createElement('div');
div.innerHTML = text;
obj.parentElement.appendChild(div);
div.addEventListener("click",
function () {
this.parentElement.removeChild(div);
}
)
}
</script>
</head>
<body>
<h3>정답의 동적 삽입</h3>
<hr>
<div><p>Q. 거울아 거울아 세상에서 누가 제일 예쁘니?</p>
<button onclick="addAnswer(this,'백설공주')">답보기</button>
</div>
<div><p>Q. 죽느냐 사느냐 어떤 것이 문제인가?</p>
<button onclick="addAnswer(this,'둘다')">답보기</button>
</div>
</body>
</html>