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

295
Visualizações
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 Respostas
Responde à pergunta

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