-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-comment-box.html
50 lines (40 loc) · 1.93 KB
/
event-comment-box.html
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
<!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>Dynamic Comment Box</title>
</head>
<body>
<h2>Add Your Comment, Please!</h2>
<section>
<h4>Your Comments:</h4>
<div id="comment-container">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Perspiciatis, consectetur assumenda inventore modi ipsa illo minus accusamus ab soluta, aperiam iusto quia in sapiente?</p>
<p>Debitis blanditiis sunt praesentium distinctio vitae minus, reiciendis at aperiam. Perferendis corporis debitis placeat ipsa qui dignissimos quis, consequuntur inventore vel id doloribus repellendus?</p>
<p>Ex ut debitis ipsa atque iure quo doloremque commodi libero. Quos sit reiciendis doloribus, velit quo ipsam illum quas aliquam consequatur, quae nisi aliquid.</p>
</div>
<p>Put your comment down below:</p>
<textarea name="" id="put-comment" cols="80" rows="8" placeholder="Write your comment here..."></textarea>
<br>
<button id="post-comment">Post</button>
</section>
<script>
// 1. add button event handler
document.getElementById('post-comment').addEventListener('click', function() {
// 2. get user comment
const commentBox = document.getElementById('put-comment');
const userComment = commentBox.value;
// 3. creat comment paragraph
const newComment = document.createElement('p');
newComment.innerText = userComment;
// 4. append or add the just written
const commentContainer = document.getElementById('comment-container');
commentContainer.appendChild(newComment);
// 5. clean the comment box
userComment.value = '';
})
</script>
</body>
</html>