const state = {
taskName: "",
tasks: [
{
id: "todo-0",
name: "Learn some frameworks!",
},
],
};Introduction to client-side frameworks / notebook
Introduction to client-side frameworks
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
function buildTodoItemEl(id, name) {
const item = document.createElement("li");
const span = document.createElement("span");
span.textContent = name;
item.id = id;
item.appendChild(span);
item.appendChild(buildDeleteButtonEl(id));
return item;
}function buildDeleteButtonEl(id) {
const button = document.createElement("button");
button.setAttribute("type", "button");
button.addEventListener("click", () => {
state.tasks = state.tasks.filter((t) => t.id !== id);
renderTodoList();
});
button.textContent = "Delete";
return button;
}