I'm currently working on a task management application, and within this app, there is a container that encompasses an input field (for entering tasks) and an icon from the font-awesome library. When the user interacts with the icon, I intend for the entire container (including the task and delete icon) to be removed. However, my initial attempts at implementing this feature have not been successful. Can someone provide guidance or assistance?
Below is the snippet of JavaScript code being used:
$(document).ready(() => {
$(".input input").on("keypress", check_todo);
$(".fa-trash").on("click", ".todo_container", delete_todo);
})
// Function to delete a task
let delete_todo = (e) => {
e.target.remove();
}
// Function to add a new task
let add_todo = () => {
let todo = $(".input input").val();
$(".output").append(`
<input type="text" placeholder="Edit To-do" value="${todo}"><i class="fa fa-trash fa-lg" aria-hidden="true"></i>
`);
$(".input input").val("");
}
// Function to validate and process a new task
let check_todo = (e) => {
if (e.keyCode == 13) {
if ($(".input input").val() == "") {
no_todo();
} else {
add_todo();
}
}
}
// Function called when no task is provided
let no_todo = () => {
alert("Please add a new todo");
}
If you would like to see the HTML structure and a demo, you can visit the following link: View here