Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
HTML
//html//


     
     <title>To-do list
     

     <h1>To Do List</h1>
     <div class="container">
          +
          <div id="toDoContainer" class="to-Dos">
          </div>
     </div>
     




//JavaScript//
let addToDoButton = document.getElementById('addToDo');
let toDoContainer = document.getElementById('toDoContainer');
let inputField = document.getElementById('inputField');

addToDoButton.addEventListener('click', () => {
     var paragraph = document.createElement('p')
     paragraph.innerText = inputField.Value;
     toDoContainer.appendChild(paragraph);
     inputField.value = "";
})


What I have tried:

try to add list. but when input something in input field its says undefined.
Posted
Updated 22-Sep-21 7:04am
v2
Comments
Member 15329613 22-Sep-21 13:53pm    
Very easy to debug.

1 solution

Probably because your getElementById calls are not finding the elements you're specifying. You never check the return values of those calls, so...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900