diff --git a/clase-9.js b/clase-9.js index d7418b1..926bc76 100644 --- a/clase-9.js +++ b/clase-9.js @@ -13,4 +13,16 @@ const resultado = document.querySelector("#resultado"); campo.addEventListener("input", () => { const cantidad = campo.value.length; resultado.textContent = `Caracteres: ${cantidad}`; -}) \ No newline at end of file +}) + +//ejercicio 3 +const lista = document.querySelector("#lista"); +lista.addEventListener("click", (e) => { + if (e.target.tagName === "LI") { + const yaSeleccionado = document.querySelector(".seleccionado"); + if (yaSeleccionado) { + yaSeleccionado.classList.remove("seleccionado"); + } + e.target.classList.add("seleccionado"); + } +}); \ No newline at end of file diff --git a/estilo.css b/estilo.css index 19d93f8..2166a6f 100644 --- a/estilo.css +++ b/estilo.css @@ -3,3 +3,9 @@ div { padding: 10px; margin: 10px; } + +li.seleccionado { + background-color: blue; + color: white; + font-weight: bold; +} \ No newline at end of file diff --git a/index.html b/index.html index 142cc6f..71c83c4 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,13 @@