Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda