diff --git a/clase-9.js b/clase-9.js index 6df1007..926bc76 100644 --- a/clase-9.js +++ b/clase-9.js @@ -1 +1,28 @@ // Agregar acá el código javascript para los ejercicios +//ejercicio 1 +const boton = document.querySelector("#boton"); +let contadorClicks = 0; +boton.addEventListener("click", () => { + contadorClicks = contadorClicks + 1; + boton.textContent = `Botón clickeado ${contadorClicks} veces`; +}) + +//ejercicio 2 +const campo = document.querySelector("#input2"); +const resultado = document.querySelector("#resultado"); +campo.addEventListener("input", () => { + const cantidad = campo.value.length; + resultado.textContent = `Caracteres: ${cantidad}`; +}) + +//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 2a6b85f..74e985a 100644 --- a/index.html +++ b/index.html @@ -9,19 +9,30 @@

Clase 9 - Eventos

- +

- + +

Caracteres: 0


- +

- +
+
+ +
+