JavaScript bindTaskEvents function isn't called 2nd time

iam making a to do list app just using javascript... in which you can add tasks edit them and delete.but my edit task function is working for the list items with which are there in html document before dom manipulation but after i add new elements it doesn't work for newly appended elements

    //Problem: User interaction doesn't provide desired results.
//Solution: Add interactivty so the user can manage daily tasks.

var taskInput = document.getElementById('new-task'); //new-task
var addButton = document.getElementsByTagName('button')[0]; //first button
var incompleteTasksHolder = document.getElementById('incomplete-tasks'); //incompleteTasks
var completedTasksHolder = document.getElementById('completed-tasks');  //completedTasks

//new task list item 
var createNewTaskElement = function(taskString){
    //create listItem
    var listItem = document.createElement('li');

    //input(checkbox)
    var checkBox = document.createElement('input');

    //label
    var label = document.createElement('label');

    //input(text)
    var editInput = document.createElement('input');

    //button.edit
    var editButton = document.createElement('button');

    //button.delete
    var deleteButton = document.createElement('button');

    //Each element needs modifying
    checkBox.type = 'checkbox';
    editInput.type = 'text';

    editButton.innerText = 'edit';
    editButton.className = 'edit';
    deleteButton.innerText = 'delete';
    deleteButton.className = 'delete';

    label.innerText = taskString;

    //Each elements needs appended
    listItem.appendChild(checkBox);
    listItem.appendChild(label);
    listItem.appendChild(editInput);
    listItem.appendChild(editButton);
    listItem.appendChild(deleteButton);

    return listItem; 
}

//Add a new task
var addTask = function(){
  //Create a new list item with the text from #new-task:
    var listItem = createNewTaskElement(taskInput.value);

    //append listItems to incomplete tasks holder
    incompleteTasksHolder.appendChild(listItem);
}

//Edit an existing task
var editTask = function(){
    console.log('the edit task function is running');
    var listItem = this.parentNode;

    var editInput = listItem.querySelector('input[type="text"]');
    var label = listItem.querySelector('label');

    var containsClass = listItem.classList.contains('editMode');
    //if the class of the parent is .editMode
    if(containsClass){
        //Switch from .editMode
        //label text become the input's value
        label.innerText = editInput.value;
    }else{
      //Switch to .editMode
      //input value becomes the label's text
        editInput.value = label.innerText;
    }
    //Toggle .editMode on the listItem
    listItem.classList.toggle('editMode');
}

//Delete an existing task
var deleteTask = function(){
    var listItem = this.parentNode;
    var ul = listItem.parentNode;
    //Remove the parent list item from the ul
    ul.removeChild(listItem);
}

//Mark a task as complete
var taskCompleted = function() {
  console.log("Task complete...");
  //Append the task list item to the #completed-tasks
  var listItem = this.parentNode;
  completedTasksHolder.appendChild(listItem);
    bindTaskEvents(listItem,taskIncomplete);
}

//Mark a task as incomplete
var taskIncomplete = function(){
    //Append the task list item to the #incomplete-tasks
    var listItem = this.parentNode;
    incompleteTasksHolder.appendChild(listItem);
    bindTaskEvents(listItem,taskCompleted);
}

//Set the click handler to the addTask function
addButton.addEventListener("click", addTask);

var bindTaskEvents = function(taskListItem, checkBoxEventHandler) {
  console.log("Bind list item events");
  //select taskListItem's children
  var checkBox = taskListItem.querySelector("input[type=checkbox]");
  var editButton = taskListItem.querySelector("button.edit");
  var deleteButton = taskListItem.querySelector("button.delete");

  //bind editTask to edit button
  editButton.onclick = editTask;

  //bind deleteTask to delete button
  deleteButton.onclick = deleteTask;

  //bind checkBoxEventHandler to checkbox
  checkBox.onchange = checkBoxEventHandler;


}

//cycle over incompletetaskHolder ul list items
for(var i = 0; i < incompleteTasksHolder.children.length; i++){
    //bind events to list's item children(taskCompleted)
    bindTaskEvents(incompleteTasksHolder.children[i], taskCompleted);
}

//cycle over completedTasksHolder ul list items
for(var i = 0; i < completedTasksHolder.children.length; i++){
  //bind events to list item's children (taskIncomplete)
  bindTaskEvents(completedTasksHolder.children[i], taskIncomplete);
}
Answer:1

This implementation seems to be working fine (Stackblitz): /** * Returns all the elements that are distinct by the * `property` value. Note that the implementation uses a `Map<...

This implementation seems to be working fine (Stackblitz): /** * Returns all the elements that are distinct by the * `property` value. Note that the implementation uses a `Map<...

I want to optionally add a key in object consider I have a following function const uploadFacebookPostWithPhoto = async (filePath, imageName, longText, linkURL, pageID, accessToken) => { ...

I want to optionally add a key in object consider I have a following function const uploadFacebookPostWithPhoto = async (filePath, imageName, longText, linkURL, pageID, accessToken) => { ...

I want to recursively sum an integer: to split an integer into an array and then sum the individual items until I am left with a single integer array. This is my logic: Take an integer (n) and ...

I want to recursively sum an integer: to split an integer into an array and then sum the individual items until I am left with a single integer array. This is my logic: Take an integer (n) and ...

  1. pass variable into bash script
  2. pass variable into awk
  3. pass variable into powershell script
  4. pass variable into sed
  5. pass variable into invoke-command
  6. pass variable into dockerfile
  7. pass variable into string python
  8. pass variable into settimeout
  9. pass variable into makefile
  10. pass variable into class python
  11. pass variable into promise
  12. pass variable into html
  13. pass variable into python script
  14. pass variable into sql query
  15. pass variable into lambda java
  16. pass variable into function powershell
  17. pass variable into openquery
  18. pass variable into onclick function
  19. pass variable into sql script
  20. pass variable into batch file

Below is my JS and then my HTML . I cannot figure out why my countdown clock doesn't automatically count down. You must refresh every second to see the correct amount of time left. Any ideas? BTW this ...

Below is my JS and then my HTML . I cannot figure out why my countdown clock doesn't automatically count down. You must refresh every second to see the correct amount of time left. Any ideas? BTW this ...

  1. javascript countdown clock code
  2. javascript countdown clock
  3. javascript countdown clock example
  4. javascript countdown clock explained
  5. js countdown clock
  6. styled javascript countdown clock
  7. javascript countdown flip clock
  8. html javascript countdown clock
  9. simple javascript countdown clock
  10. javascript digital countdown clock
  11. free javascript countdown clock
  12. javascript timer countdown clock
  13. javascript countdown analog clock
  14. javascript display countdown clock
  15. javascript multiple countdown clock
  16. moment js countdown clock
  17. react js countdown clock
  18. javascript countdown timer flip clock
  19. javascript countdown to date flip clock
  20. javascript countdown/count-up timer/clock/ticker for web pages