this is a todolist that should delete when the button is clicked. it has an icon within. It deletes when button is clicked but nothing happens when icon is clicked. i have tried adding (!important) to the pointer events but it wont let the icon take the functionality of the parent.
MORE DETAILS HAVE BEEN ADDED
<script>
//selectors
const todoInput = document.querySelector(".todo-input");
const todoButton = document.querySelector(".todo-button");
const todoList = document.querySelector(".todo-list");
//eventlistners
todoButton.addEventListener("click", addTodo);
todoList.addEventListener('click', deleteCheck);
//functions
function addTodo(event){
//prevent form submit
event.preventDefault();
//TODO DIV
const todoDiv = document.createElement("div");
todoDiv.classList.add("todo");
//create li
const newTodo = document.createElement('li');
newTodo.innerText = todoInput.value;
newTodo.classList.add('todo-item');
todoDiv.appendChild(newTodo);
//trash button
const trashButton = document.createElement('button');
trashButton.innerHTML = '<i class="fas fa-trash"></i>';
trashButton.classList.add("trash-btn");
todoDiv.appendChild(trashButton);
//append to list
todoList.appendChild(todoDiv);
//clear
todoInput.value = "";
}
function deleteCheck(e) {
console.log(e.target);
const item = e.target;
//DELETE TODO
if (item.classList[0] === 'trash-btn') {
const todo = item.parentElement;
//animation
todo.classList.add("fall");
todo.addEventListener('transitionend', function(){
todo.remove();
});
}
}
</script>
THIS IS CSSSSSSSSSSSSSSSSSSSSSSSSSSS
<style>
body{
color: whitesmoke;
}
header, form{
min-height:20vh;
display:flex;
justify-content: center;
align-items: center;
}
form input, form button{
padding: 0.5rem;
font-size: 2rem;
border:none;
background-color: whitesmoke;
}
form button{
color: black;
background: whitesmoke;
cursor: pointer;
transition: all 0.5s ease;
}
form button:hover{
background: black;
color: whitesmoke;
}
.todo-container{
display:flex;
justify-content: center;
align-items:center;
}
.todo-list{
min-width: 30%;
list-style: none;
}
.todo{
background :whitesmoke;
color:black;
font-size: 1.5rem;
display:flex;
justify-content: space-between;
align-items: center;
transition: all 0.5 ease;
}
.todo li{
flex: 1;
}
.trash-btn{
background: red;
color:whitesmoke;
border: none;
padding: 1rem;
cursor: pointer;
font-size: 1rem;
}
.fa-trash{
pointer-events: none ;
}
.fall{
transform: translateY(8rem) rotateZ(20deg);
opacity:0;
}
</style>
HTMLLLLLLLLLLLLLLLLLLLLLLLLLLLL HERE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>everyday</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width" initial-scale="1.0">
<link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
<script src="https://use.fontawesome.com/releases/v5.13.0/js/all.js" data-auto-replace-svg="nest"></script>
</head>
<body>
<header>
<h1> To do List</h1>
</header>
<form>
<input type="text" class="todo-input">
<button class="todo-button" type ="submit"><i class = "fas fa-plus-square"></i></button>
</form>
<div class="todo-container">
<ul class="todo-list">
</ul>
</div>
</body>