feat: add item list with click event to toggle selection

This commit is contained in:
2026-05-25 12:17:39 -03:00
parent 927173b159
commit 28718fea20
3 changed files with 17 additions and 1 deletions

View File

@@ -1 +1,7 @@
// Agregar aquí el código javascript
document.getElementById('itemList').addEventListener('click', (event) => {
if (event.target.tagName === 'LI') {
event.target.classList.toggle('selected');
}
});

View File

@@ -1,2 +1,5 @@
/* Agregar el código CSS necesario para el ejercicio */
.selected {
background-color: lightblue;
}

View File

@@ -8,7 +8,14 @@
</head>
<body>
<h1>Ejercicio 3</h1>
<ul id="itemList">
<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>