Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
How to grab the value from an input and store the input value as the text of a new list item?

When the user clicks the button with the ID of generate-todo, I want to grab the value from the input with the ID of new-todo, and store the input value as the text of a new list item and append that new item to the unordered list with the class of todos. This is what I've tried so far but I'm missing something.

  let todo = document.querySelector('#generate-todo').addEventListener('click', function() { 
        todo = document.querySelector('#new-todo').value;
      const create = document.createElement('li');
      document.querySelector('.todos').append(create);  
  });
<label for="new-todo">Add a new item to the list:</label>
<input id="new-todo" type="text">
<button id="generate-todo">Add to the List!</button>
<h1>List of things to do</h1>
<ul class="todos">
</ul>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

this should get you started

document.getElementById('generate-todo').addEventListener('click', function() { 
        let todo = document.getElementById('new-todo').value;
      const li = document.createElement('li');
      li.innerText = todo;
      document.getElementById('todos').append(li);  
  });
<label for="new-todo">Add a new item to the list:</label>
<input id="new-todo" type="text">
<button id="generate-todo">Add to the List!</button>
<h1>List of things to do</h1>
<ul id="todos">
</ul>

about 4 years ago · Juan Pablo Isaza Report

0

You are missing a . in todos selector.

document.querySelector(".todos").append(create)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!