Compare commits
1 Commits
solucion-e
...
solucion-e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4429e93eaf |
@@ -1 +1,22 @@
|
||||
// Agregar aquí el código javascript
|
||||
const boton = document.querySelector("#agregar");
|
||||
|
||||
boton.addEventListener("click", () => {
|
||||
const campo = document.querySelector("#agregar input");
|
||||
const texto = campo.value.trim();
|
||||
|
||||
const lista = document.querySelector("#lista ul");
|
||||
|
||||
// Si el campo está vacío, no hacemos nada.
|
||||
if (texto === "") return;
|
||||
|
||||
// Creamos el nuevo ítem y lo agregamos a la lista.
|
||||
const item = document.createElement("li");
|
||||
item.textContent = texto;
|
||||
lista.appendChild(item);
|
||||
|
||||
// Limpiamos el campo para que el usuario pueda escribir la próxima tarea.
|
||||
campo.value = "";
|
||||
// Ponemos el cursor nuevamente en el campo:
|
||||
campo.focus();
|
||||
});
|
||||
|
||||
@@ -8,6 +8,16 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ejercicio 2</h1>
|
||||
<div id="lista">
|
||||
<h2>Lista de tareas</h2>
|
||||
<ul>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div id="agregar">
|
||||
<input type="text" placeholder="Descripción de la nueva tarea">
|
||||
<button type="button">Agregar tarea</button>
|
||||
</div>
|
||||
|
||||
<script src="ejercicio2.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -1,11 +1 @@
|
||||
const lista = document.querySelector("#lista");
|
||||
|
||||
// Un solo listener en la lista, no uno por ítem (delegación de eventos).
|
||||
lista.addEventListener("click", (e) => {
|
||||
// Verificamos que el clic fue sobre un <li>. Si fue sobre otro elemento,
|
||||
// retornamos sin hacer nada.
|
||||
if (e.target.tagName !== "LI") return;
|
||||
|
||||
// toggle agrega la clase si no la tiene, y la quita si ya la tenía.
|
||||
e.target.classList.toggle("seleccionado");
|
||||
});
|
||||
// Agregar aquí el código javascript
|
||||
|
||||
@@ -1,5 +1,2 @@
|
||||
.seleccionado {
|
||||
background-color: yellow;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Agregar el código CSS necesario para el ejercicio */
|
||||
|
||||
|
||||
@@ -9,15 +9,6 @@
|
||||
<body>
|
||||
<h1>Ejercicio 3</h1>
|
||||
|
||||
<ul id="lista">
|
||||
<li>Elemento 1</li>
|
||||
<li>Elemento 2</li>
|
||||
<li>Elemento 3</li>
|
||||
<li>Elemento 4</li>
|
||||
<li>Elemento 5</li>
|
||||
<li>Elemento 6</li>
|
||||
</ul>
|
||||
|
||||
<script src="ejercicio3.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user