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

173
Views
Can multiple elements in a node list respond to an event listener?

I have added the li variable using querySelectorAll, but when I attempt to add an event listener to it to change the textDecoration style to line-through, I am not having any success. Any ideas?

// Variables
let addBtn = document.querySelector("#addBtn");
let input = document.querySelector("#input");
let ul = document.querySelector("ul");
let li = document.querySelectorAll("li");
let completeBtn = document.querySelector("#complete-btn");

// Functions
function inputLength() {
  return input.value.length;
}

function createListElement() {
  let li = document.createElement("li");
  li.appendChild(document.createTextNode(input.value));
  ul.appendChild(li);
  input.value = "";
}

function addListAfterClick() {
  if (inputLength() > 0) {
    createListElement();
  }
}

function addListAfterKeypress(e) {
  if (inputLength() > 0 && event.keyCode === 13) {
    createListElement();
  }
}

function done() {
  li.style.textDecoration = "line-through";
}

// Event Listeners
addBtn.addEventListener("click", addListAfterClick);

input.addEventListener("keypress", addListAfterKeypress);

// I would like to add an event listener here so that the li elements textDecoration is changed to "line-through"

completeBtn.addEventListener("click", function complete() {
  alert("Congratulations! You won't starve this week.");
  console.log(completeBtn);
  completeBtn.style.display = "none";
});

about 4 years ago · Santiago Gelvez
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!