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

110
Visualizações
make second button draw a line on the completed task

I am trying to draw a line throuh the task once the "done" button is pushed but i can't seem to put in the right code.

'''

function addTask() {
  let input = document.getElementById("task").value;
  if (input == "") {
    window.alert("You must enter a value in the New Task field.");
  } else {
    let taskList = document.getElementById("lista");
    taskList.innerHTML +=
      `<li ><span id=${input} >` +
      input +
      "</span ><button onclick='this.parentNode.parentNode.removeChild(this.parentNode)'           class='delete'>Delete</button> <button onclick='document.getElementByTagName('span').style.textDecoration = 'line-through''    class='done'>Done</button>";
   }
 }

'''

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

<button onclick='document.getElementByTagName('span').style.textDecoration = 'line-through''

I am not entirely sure but it looks like you have an extra apostrophe sitting next to 'line-through'

What happens if you try to execute the code? Do you have some sort of fiddle available? Then i can investigate further.

about 4 years ago · Juan Pablo Isaza Relatório

0

Your main problem is that when trying to target the task name, you're using a document.getElementByTagName('span'). So this is going to look at the whole document and find the first span while what you actually need is to search locally. The querySelector() method is easy to use since you can just use css selectors.

const input = document.getElementById('task');
function addTask(){
    const taskName = input.value;
    //check if task name isn't empty
    const newTask = `
    <li>
       <span>${taskName}</span>
       ...
       <button onclick = "this.parentNode.querySelector('span').style.textDecoration = 'line-through'">Done</button>
    </li>
    `;
    //append this to the task list
}
about 4 years ago · Juan Pablo Isaza Relatório
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