Skip to content

Commit

Permalink
To-do-list
Browse files Browse the repository at this point in the history
  • Loading branch information
idrax47 committed Nov 18, 2024
1 parent 10c9b55 commit fe0488b
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
22 changes: 22 additions & 0 deletions To-do-list/To-do-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lista de Tareas</title>
<link rel="stylesheet" href="to-do-list.css">
</head>
<body>
<header>
<h1>Lista de Tareas</h1>
</header>
<main>
<div id="todo-app">
<input type="text" id="task-input" placeholder="Escribe una tarea...">
<button id="add-task-btn">Agregar Tarea</button>
<ul id="task-list"></ul>
</div>
</main>
<script src="to-do-list.js"></script>
</body>
</html>
65 changes: 65 additions & 0 deletions To-do-list/to-do-list.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
text-align: center;
}

#todo-app {
margin: 50px auto;
width: 300px;
padding: 20px;
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

#task-input {
width: 80%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
}

#add-task-btn {
padding: 10px 20px;
background-color: #007acc;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

#add-task-btn:hover {
background-color: #005fa3;
}

#task-list {
list-style: none;
padding: 0;
}

#task-list li {
background-color: #e3e3e3;
margin: 5px 0;
padding: 10px;
border-radius: 5px;
display: flex;
justify-content: space-between;
align-items: center;
}

.delete-btn {
background-color: #ff4d4d;
color: white;
border: none;
border-radius: 5px;
padding: 5px 10px;
cursor: pointer;
}

.delete-btn:hover {
background-color: #d93636;
}
49 changes: 49 additions & 0 deletions To-do-list/to-do-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Selección de elementos
const taskInput = document.getElementById("task-input");
const addTaskBtn = document.getElementById("add-task-btn");
const taskList = document.getElementById("task-list");

// Función para agregar una tarea
function addTask() {
const taskText = taskInput.value.trim(); // Elimina espacios en blanco

if (taskText === "") {
alert("Escribe una tarea antes de agregarla.");
return;
}

// Crear un elemento <li>
const taskItem = document.createElement("li");

// Añadir el texto de la tarea
taskItem.textContent = taskText;

// Botón para eliminar la tarea
const deleteBtn = document.createElement("button");
deleteBtn.textContent = "Eliminar";
deleteBtn.classList.add("delete-btn");

// Evento para eliminar la tarea
deleteBtn.addEventListener("click", () => {
taskItem.remove();
});

// Añadir el botón al <li>
taskItem.appendChild(deleteBtn);

// Añadir el <li> al <ul>
taskList.appendChild(taskItem);

// Limpiar el campo de entrada
taskInput.value = "";
}

// Evento para el botón de agregar
addTaskBtn.addEventListener("click", addTask);

// Evento para agregar con la tecla "Enter"
taskInput.addEventListener("keypress", (event) => {
if (event.key === "Enter") {
addTask();
}
});
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h2>Sobre mí</h2>
<h2>Proyectos</h2>
<p>
<a href="Calculadora/calculadora.html">Calculadora Básica</a>
<a href="To-do-list/To-do-list.html">Lista De Tareas</a>
</p>
</section>
<section id="contacto">
Expand Down

0 comments on commit fe0488b

Please sign in to comment.