1

I am creating a "to do list" javascript practice app.

I have an input, and a "submit button". the submit button uses the text in the input.value. The submit button has an onclick that creates a new div with a nested h3 with the text from the input.value. The submit button also creates an "x button" and a "complete button"

How can I create an onclick function for the "x button" which doesn't exist in the DOM until after I use the submit button?

I want the "x button" to delete the entire div that was created with the submit button that includes the aforementioned x button itself, as well as the h3 and complete button that were created with the submit button.

mojo42
  • 11
  • 1
  • You need to do something like this: var button = document.createElement("button"); button.addEventListener("click", function() { var myDiv = document.querySelector("#myDiv"); myDiv.parentNode.removeChild(myDiv); }); No idea why do someone linked you agains jquery responses when this is a javascript question. – String Manolo Sep 28 '20 at 00:23

0 Answers0