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

290
Views
Creating a do list using javascript ( How to delete the function by just clicking on the list element?)

I am planning to create a simple to-do list to teach my students( I am also very new to JS)

function createlist() {
  let x = document.forms["todo"]["thing"].value;
  var head = document.createElement("li");
  head.innerText = x;
  head.style.color = "red";
  head.setAttribute("id", "listid");
  document.getElementById("myUL").appendChild(head);
}

I want the list elements to be deleted when I click on them! How do I dynamically create an event and link it to the list element created?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Attach a single event listener to the list element to catch events from your list elements as they "bubble up" the DOM, and then add a class to the clicked item that sets its display to none.

const list = document.querySelector('ul');
list.addEventListener('click', handleClick, false);

function handleClick(e) {
  e.target.classList.add('deleted');
}
.deleted { display: none; }
li:hover { cursor: pointer; color: blue; }
<ul>
  <li>One</li>
  <li>Two</li>
  <li>Three</li>
  <li>Four</li>
</ul>

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!