Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
How to add a <tr> so that the tasks can be shown 1 after the other in a JS/CSS/HTML To-Do List?

So in a to-do list project, I wrote this:

 <table id="list">
      <tr>
        <span id="task" />
        <input id="inTask" placeholder="Add Task" />
      </tr>
    </table>
    <button id="addTask" type="button" onclick="addTask()">+</button>

Which is supposed to add an Input onclick, and show the previous input value above the input field. Here is the JavaScript function:

  function addTask() {
    let table = document.getElementById("list");
    let input =
      '<tr><span id="task" /><input id="inTask" placeholder="Add Task" /></tr>';

    let task = document.getElementById("inTask").value;

    if (task !== "") {
      document.getElementById("task").innerText = task;
      document.getElementById("list").innerHTML += input;

    }
  }

The problem is that when I add a task, the input field is added, but then when I type a task in the new input field, it show the value of the new input instead of the old, you can try it to understand: https://t3wth8.csb.app And I am out of ideas on how to fix that.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda