-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters