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

136
Visualizações
i can't make a button work, i've tried the eventListener and the onclick

please if someone would be so kind and help me, i would be very happy, clearing i'm a beginner so help if you can, please.

the html

<div>
    <h2>TO-DO LIST</h2>
    <input type="text" id="tasks"  class="List" placeholder="add">
    <input type="submit" id="subButton" onclick="action()">
    <!-- <button type="button" id='resetBut' onclick="deleteIl()">Reset</button>-->
    <div>

   <ul id="myUl" ></ul>

the js

function action() {

  let item = document.createElement('li');
  let inputValue = document.getElementById('tasks').value;
  var t = document.createTextNode(inputValue);
  item.appendChild(t);

  if (inputValue === '') {
    alert("you must write something!");
  } else {
    document.getElementById('myUl').appendChild(item);
  }
  document.getElementById('tasks').value = '';

  const tasksDelete = document.createElement("button");
  tasksDelete.classList.add("delete");
  tasksDelete.innerHTML = 'X';
  item.appendChild(tasksDelete);
  document.getElementsByClassName("delete").onclick = log();
  //document.getElementsByClassName("delete").addEventListener("click", log());

  function log() {
    console.log("name")
  }
  //tasksDelete.document.getElementById('myUl');
  //tasksDelete.removeChild();
}

i'm trying to put a delete button on the elements 'li' (this works), and trying to use the removeChild() but i'm getting 'Uncaught ReferenceError: removeChild is not defined', so to see if it's working i've change the removeChild() for the log function, and now the log function appears in the console when a press the subButton and not when i click on the delete button.

about 4 years ago · Juan Pablo Isaza
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