<main>
<h1>TODOLIST</h1>
<div class="addTask">
<input type="text" id="newTask" placeholder="Enter task...">
<button id="addTaskButton">ADD</button>
</div>
<div class="currentTasks">
<ul id="list">
</ul>
</div>
</main>
<footer>Hecho por Ricardo Nardochone 2022</footer>
<script src="script.js"></script>
*, *::after, *::before{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}
body{
display: flex;
flex-direction: column;
}
main{
background-color: white;
position: absolute;
width: 400px;
padding: 20px;
left: 20px;
right: 20px;
margin: 50px auto;
border-radius: 20px;
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.349);
display: flex;
flex-direction: column;
justify-content: start;
align-items: center;
}
h1{
color: rgb(44, 116, 252);
}
.addTask{
position: relative;
width: 350px;
height: 40px;
margin-bottom: 20px;
}
#newTask {
display: inline-block;
width: 100%;
height: 100%;
padding: 15px 80px 15px 15px;
border: 2px solid rgb(44, 116, 252);
outline: none;
border-radius: 30px;
font-size: 16px;
}
#addTaskButton {
position: absolute;
display: inline-block;
cursor: pointer;
width: 70px;
height: 30px;
right: 5px;
top: 5px;
border-radius: 30px;
border: none;
background-color: rgb(44, 116, 252);
font-weight: 600;
color: white;
font-size: 16px;
box-shadow: 2px 2px 5px rgba(128, 128, 128, 0.438);
outline: none;
}
#addTaskButton:active{
top:6px;
background-color:rgb(39, 102, 219);
}
ul li {
display: flex;
border-bottom: 2px solid black;
width: 340px;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
ul li p{
word-wrap: break-word;
word-break: break-all;
}
ul li::marker {
color: red;
font-size: 1.5em;
}
ul li button{
min-width: 20px;
height: 20px;
background-color: red;
padding: 0px;
line-height: 0;
border-radius: 50%;
border: none;
cursor: pointer;
transition: transform 0.3s;
margin-left: 10px;
}
ul li button:hover{
transform: scale(1.4);
}
ul li button:active{
background-color:rgb(179, 0, 0);
}
footer{
position: fixed;
bottom: 0;
right: 10px;
font-size: 15px;
color: rgb(44, 116, 252);
z-index: -1;
}
const addButton = document.getElementById("addTaskButton");
const elementToAdd = document.getElementById("newTask");
//listener to enter key
document.addEventListener("keyup", function(event) {
if (event.key === 'Enter') {
addElement ();
}
});
//Listener to add button
addButton.addEventListener("click", () => {
addElement();
});
function addElement (){
if(elementToAdd.value == "") return;
addElementToList(elementToAdd.value);
elementToAdd.value = "";
}
function addElementToList(element) {
var ul = document.getElementById("list");
var li = document.createElement("li");
var button = document.createElement("button");
var textP = document.createElement("p");
button.classList.add("deleteButton");
button.innerHTML = "✖";
button.addEventListener("click", () => {
deleteTask(li);
});
button.addEventListener("mouseover", () => {
changeStyle(textP);
});
button.addEventListener("mouseout", () => {
normalStyle(textP);
});
textP.appendChild(document.createTextNode("● "+element));
li.appendChild(textP);
li.appendChild(button);
ul.appendChild(li);
}
function deleteTask (task){
task.remove();
}
function changeStyle(t){
t.style.textDecoration = "line-through";
}
function normalStyle(t){
t.style.textDecoration = "none";
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.