forked from marquez.juan/clase-10-ejercicios-de-repaso
ejercicio 3: resaltador de items con delegacion de eventos
This commit is contained in:
@@ -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');
|
||||||
|
});
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user