So I have a function: createTodo(title)
which takes in a title and for that title generates a “todo_block” div that has the text, and a remove button, within the function I attempt to set the event listener for the remove button to remove said todo block if it’s clicked, but it doesn’t seem to be working despite following jquery docs as well as having no errors. Here’s the code for the function:
function createTodo(title) {
let todo = $("<div>").html(`<h3 class="todo_text">${title}</h3>
<button class="remove_todo">
Remove
</button>`);
todo.addClass("todo_block")
todo.find(".remove_button").click(async (e) => {
e.preventDefault();
todo.remove();
});
todo_display.append(todo);
}
Before it turned out I wasn’t selecting it properly (was trying to use jquery methods on elements that weren’t selected using jquery). Now that’s changed and there’s no issue in that aspect, yet for some reason it doesn’t work.