diff --git a/clase-9.js b/clase-9.js index 2420256..f6f0063 100644 --- a/clase-9.js +++ b/clase-9.js @@ -20,4 +20,23 @@ const contadorCaracteres = document.querySelector("#cantidadCaracteres"); campo.addEventListener("input", function() { contadorCaracteres.textContent = `Cantidad de caracteres: ${campo.value.length}`; +}); + + + +//Ejercicio 3 de la clase 9" + +const lista = document.querySelector("#lista"); +lista.addEventListener("click", function(event) { + if (event.target.tagName === "LI") { + + const items = document.querySelectorAll("#lista li"); + + for (const item of items) { + item.classList.remove("seleccionado"); + }; + + event.target.classList.add("seleccionado"); + console.log(event.target.textContent); + } }); \ No newline at end of file diff --git a/estilo.css b/estilo.css index 19d93f8..658df39 100644 --- a/estilo.css +++ b/estilo.css @@ -3,3 +3,8 @@ div { padding: 10px; margin: 10px; } + +.seleccionado { + background-color: yellow; + font-weight: bold; +} diff --git a/index.html b/index.html index 22e35d3..15bcbd7 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,13 @@
+