1 Commits

Author SHA1 Message Date
Juanse Marquez
b459ca529a Solución ejercicio 3 2026-06-01 18:47:31 -03:00
3 changed files with 24 additions and 2 deletions

View File

@@ -1 +1,11 @@
// Agregar aquí el código javascript 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");
});

View File

@@ -1,2 +1,5 @@
/* Agregar el código CSS necesario para el ejercicio */ .seleccionado {
background-color: yellow;
font-weight: bold;
}

View File

@@ -9,6 +9,15 @@
<body> <body>
<h1>Ejercicio 3</h1> <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> <script src="ejercicio3.js"></script>
</body> </body>
</html> </html>