Menu
I am working on my first website and I’m working on the comment section. This is the code I wrote for adding a comment:
<script>
const userComments = [];
render();
function SendComment() {
const textbox = document.getElementById('writebox-id');
const title = textbox.value;
userComments.push(title);
render();
}
function render() {
// reset our list
document.getElementById('user-comment-id').innerHTML = '';
userComments.forEach(function (comment) {
const element = document.createElement('div');
element.innerText = comment;
const commentList = document.getElementById('user-comment-id');
commentList.appendChild(element);
});
}
</script>
But my website does not show inside the other elements in div, only shows the CSS part, which includes user-comment class properties. This is the the div section:
<div class="user-comment" id="user-comment-id">
<img class="sender-pitcure"
src="pp/ben.png" >
<p class="user-text">
Hello
</p>
<div ></div>
</div>
and the CSS part:
.user-comment{
margin-top: 82px;
outline: 2px solid lavender;
margin-bottom: 6px;
width: 380px;
}
Shortly, this is how my website looks like:
But this is what I want to do:
Also, I cannot set the div, when there are so many comments it goes down and make the post extra longer. Can I restrict this?
I would be really happy to find a solution to these. Can you help me please?