html
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
<!-- Check out the current version in the comments -->
<!DOCTYPE html>
<html>
<head>
<title>Comment demo</title>
</head>
<body>
<div class="container">
<div class="header">
<h2>Comment Demo</h2>
</div>
<h4>Enter some text below to make a comment</h4>
<textarea></textarea><br>
<button>Enter</button>
<div class="comments">
comments here:
</div>
<script>
let text = document.querySelector("textarea");
let btn = document.querySelector("button");
btn.addEventListener("click", function(){
let newCom = document.createElement('div');
newCom.id = "comment";
let newComData = document.createTextNode(text.value);
newCom.appendChild(newComData);
document.querySelector(".comments").appendChild(newCom);
text.value = "";
});
Enter to Rename, Shift+Enter to Preview
css
css
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
*{
padding: 0px;
margin: 0px;
}
body, .container, .comments {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
button{
color: black;
border-style: none;
padding: 5px;
font-size: 100%;
}
.comments{
background-color: lightgray;
width: auto;
height: fit-content;
margin-top: 30px;
border: solid 1px black;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run