lundi 2 juillet 2018

Find all checked checkbox which are dynamically added

I am making a simple to do list app. I want to find which tasks have been checked after added and do a line-through on the specific task. How do I do that?

Binding a change event to each task created seems inefficient. How to I proceed from here?

document.getElementById('taskForm').addEventListener('submit',displayTask);

function displayTask(e){
  let task = document.getElementById('taskInput').value;
  let div = document.createElement('div');

  div.innerHTML = `<input type="checkbox">${task}`

  document.getElementById('taskContainer').appendChild(div)
  e.preventDefault();
}
<form id="taskForm">
  <input type="text" id="taskInput" required>
  <input type="submit" value="Add">
</form>

<div id="taskContainer"></div>



Aucun commentaire:

Enregistrer un commentaire