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

226
Views
Why is the input not being added to the list?

I am trying to make a simple to-do list, previously I got it working but now that I've tried adding a feature that checked if the input is empty - it is no longer working, clicking the add button does not do anything.

My code :

function addLi() {
  var li = document.createElement("li");
  var input = document.getElementById("TaskText").value;
  var txtNode = document.createTextNode(input);

  li.appendChild(txtNode);
  if (input === '') {
    alert("Must write a task!");
  } else {
    document.getElementById("list");appendChild(li)
  }
  document.getElementById("TaskText").value = "";
}
<body>

  <h1>Your To-Do List</h1>
  <label>Add a task to your list</label> <br>
  <input type="text" placeholder="Add task..." id="TaskText">
  <button onclick="addLi()" id="AddTask">Add</button>

  <ul id="list">
    <li>This is an example of a task!</li>
  </ul>

</body>

about 4 years ago · Juan Pablo Isaza
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!