I am trying to input a new task. It will only allow me to add one task. If I input another it just removes the last. How can I save multiple?
HTML Code:
JavaScript
x
16
16
1
<h2>Future Projects</h2>
2
<div id="projects">
3
<div class="project">first</div>
4
<div class="project">y</div>
5
<div class="project">last</div>
6
</div>
7
<form action="index.html" get>
8
<label for="message">Meaningful Message:</label>
9
<br>
10
<textarea name="message" id="message" rows="1" cols="20">
11
</textarea>
12
<br>
13
<input type="submit" value="submit">
14
</form>
15
</div>
16
JS Code:
JavaScript
1
10
10
1
const message = words.get('message');
2
if(message.value !== '') {
3
let e = document.createElement('div')
4
e.innerHTML = `${message}`
5
e.className = 'project'
6
let parent = document.getElementById('projects')
7
parent.append(e);
8
e.preventDefault()
9
}
10
Advertisement
Answer
Try apppendChild.
JavaScript
1
7
1
const project = document.createElement("div");
2
project.innerText = "text";
3
//...
4
5
const parent = document.getElementById('projects');
6
parent.appendChild(project);
7