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

143
Views
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
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!