Absolute beginner programmer here. I'm trying to create a comments box where whatever you type in the comments, will be stored in another div. I got some of it to work, it was able to append however, it disappears straight after. I want it to store the comments in the #comment-box div and when you enter another comment it stores it underneath. Here is my code so far
<div class="container">
<h2>Leave us a comment</h2>
<form>
<textarea id="" placeholder="Add Your Comment" value=" "></textarea>
<div class="btn">
<input id="submit" type="submit" value="Comment">
<button id="clear">
🙏</button>
</div>
</form>
</div>
<div class="comments">
<h2>Comments</h2>
<div id="comment-box" value="submit">
</div>
</div>
and my JS is
const field = document.querySelector('textarea');
const backUp = field.getAttribute('placeholder')
const btn = document.querySelector('.btn');
const clear = document.getElementById('clear')
const submit = document.querySelector('#submit')
// const comments = document.querySelector('#comment-box')
const comments = document.getElementById('comment-box')
field.onfocus = function(){
this.setAttribute('placeholder','')
this.style.borderColor = '#333'
btn.style.display = 'block'
} // when clicking on this, placeholder changes into ' '.
field.onblur = function(){
this.setAttribute('placeholder',backUp)
} //click away, placeholder returns
clear.onclick = function(){
btn.style.display = 'none';
field.value = ' '
submit.onclick = function(){
submit.style.display = 'none';
const content = document.createTextNode(field.value)
comments.appendChild(content)
Where am I going wrong guys? Any feedback would be appreciated. Thank You