diff --git a/clase-9.js b/clase-9.js index 50640d9..d7804ba 100644 --- a/clase-9.js +++ b/clase-9.js @@ -15,4 +15,19 @@ const parrafo2 = document.querySelector("#contadorCaracteres"); campo.addEventListener("input", (e) => { parrafo2.textContent = `El campo de texto tiene ${e.target.value.length} caracteres`; console.log(e.target.value); +}); + +const lista = document.querySelector("ul"); + +lista.addEventListener("click", (e) => { + if (e.target.tagName === "LI") { + const items = document.querySelectorAll("li") + for (const item of items) { + item.classList.remove("seleccionado"); + } + + e.target.classList.add("seleccionado"); + + console.log(e.target.textContent); + } }); \ No newline at end of file diff --git a/index.html b/index.html index 43bee2d..7bb9aeb 100644 --- a/index.html +++ b/index.html @@ -19,7 +19,13 @@