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

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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