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

108
Views
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 answers
Answer question

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 Report

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 Report
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!