Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add task to tasklist from JS to HTML page

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:

            <h2>Future Projects</h2>
            <div id="projects">
                <div class="project">first</div>
                <div class="project">y</div>
                <div class="project">last</div>
            </div>
            <form action="index.html" get>
                <label for="message">Meaningful Message:</label>
                        <br>
                        <textarea name="message" id="message" rows="1" cols="20">
                        </textarea>
                    <br>
                    <input type="submit" value="submit">
            </form>
        </div>

JS Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const message = words.get('message');
if(message.value !== '') {
    let e = document.createElement('div')
    e.innerHTML = `${message}`
    e.className = 'project'
    let parent = document.getElementById('projects')
    parent.append(e);
    e.preventDefault()
}

>Solution :

Try apppendChild.

const project = document.createElement("div");
project.innerText = "text";
//...

const parent = document.getElementById('projects');
parent.appendChild(project);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading