Agrega ejercicio 3 de la clase 9

This commit is contained in:
Lucio Gaibazzi
2026-05-30 22:00:14 -03:00
parent f8ec466ac7
commit 1b5e549a8f
3 changed files with 31 additions and 0 deletions

View File

@@ -20,4 +20,23 @@ const contadorCaracteres = document.querySelector("#cantidadCaracteres");
campo.addEventListener("input", function() { campo.addEventListener("input", function() {
contadorCaracteres.textContent = `Cantidad de caracteres: ${campo.value.length}`; 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);
}
}); });

View File

@@ -3,3 +3,8 @@ div {
padding: 10px; padding: 10px;
margin: 10px; margin: 10px;
} }
.seleccionado {
background-color: yellow;
font-weight: bold;
}

View File

@@ -22,6 +22,13 @@
<hr> <hr>
<div id="ejercicio-3"> <div id="ejercicio-3">
<!-- Agregar acá el código HTML que haga falta para el ejercicio 3 --> <!-- Agregar acá el código HTML que haga falta para el ejercicio 3 -->
<ul id="lista">
<li>Audi</li>
<li>Toyota</li>
<li>Chevrolet</li>
<li>Ford</li>
<li>Nissan</li>
</ul>
</div> </div>
<hr> <hr>
<div id="ejercicio-4"> <div id="ejercicio-4">