Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addEventListenersToElement(element) {
- element.addEventListener("click", () => {
- element.classList.toggle("done");
- });
- var deleteButton = element.querySelector("button");
- deleteButton.addEventListener("click", () => {
- element.remove();
- });
- }
- function addEventListenersToListElements() {
- var liArray = document.querySelectorAll("li");
- liArray.forEach(addEventListenersToElement);
- }
- function createListElement() {
- var li = document.createElement("li");
- li.appendChild(document.createTextNode(input.value + " "));
- var deleteButton = document.createElement("button");
- deleteButton.appendChild(document.createTextNode("Delete"));
- li.appendChild(deleteButton);
- ul.appendChild(li);
- input.value = "";
- addEventListenersToElement(li);
- }
- // Call addEventListenersToListElements() once initially
- addEventListenersToListElements();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement