function editTodo(index) {
const $todoText = $todoList.children[index].querySelector('.todo');
const $paragraph = $todoText.querySelector('p');
const $input = document.createElement('input');
$input.type = 'text';
$input.className = 'todo-input';
$input.value = $paragraph.textContent;
$todoText.removeChild($paragraph);
$todoText.appendChild($input);
$input.focus();
$input.addEventListener('blur', () => {
todoList[index].content = $input.value;
saveTodoList();
renderTodoList();
console.log("[update] " + index + " element edited to " + $input.value);
});
}
function renderTodoList() {
$todoList.innerHTML = '';
todoList.forEach((todo, index) => {
const $newTodo = createTodoItem(todo.content, index);
$todoList.appendChild($newTodo);
const $checkbox = document.getElementById('checkbox-' + index);
$checkbox.checked = todoList[index].completed;
});
console.log("[system] todolist rendered");
}
...
function toggleComplete(index) {
if (index >= 0 && index < todoList.length) {
todoList[index].completed = !todoList[index].completed;
saveTodoList();
const $checkbox = document.getElementById('checkbox-' + index);
$checkbox.checked = todoList[index].completed;
}
console.log("[update] " + index + " element completed toggle changed");
}