ejercicio 3: resaltador de items con delegacion de eventos

This commit is contained in:
2026-05-28 13:27:31 -03:00
parent 9dee9e34ad
commit ee4770f32c
3 changed files with 26 additions and 2 deletions

View File

@@ -1 +1,11 @@
// Agregar aquí el código javascript const listaItems = document.getElementById('lista-items');
listaItems.addEventListener('click', (event) => {
const item = event.target;
if (item.tagName.toLowerCase() !== 'li') {
return;
}
item.classList.toggle('seleccionado');
});

View File

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

View File

@@ -2,13 +2,22 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 3</title> <title>Ejercicio 3</title>
<link rel="stylesheet" href="estilo.css"> <link rel="stylesheet" href="estilo.css">
</head> </head>
<body> <body>
<h1>Ejercicio 3</h1> <h1>Ejercicio 3</h1>
<ul id="lista-items">
<li>Zapatos nuevos</li>
<li>Leer un capítulo</li>
<li>Comprar frutas</li>
<li>Enviar el informe</li>
<li>Escuchar música</li>
<li>Practicar JavaScript</li>
</ul>
<script src="ejercicio3.js"></script> <script src="ejercicio3.js"></script>
</body> </body>
</html> </html>