Compare commits

4 Commits

3 changed files with 67 additions and 5 deletions

View File

@@ -1 +1,32 @@
// Agregar acá el código javascript para los ejercicios
// Ejercicio 1 - Contador de clics
let clickCount = 0;
const boton = document.getElementById('miBoton');
const parrafo = document.getElementById('contadorClicks');
boton.addEventListener('click', function() {
clickCount++;
parrafo.textContent = `Botón clickeado ${clickCount} veces`;
});
// Ejercicio 2 - Contador de caracteres en tiempo real
const campoTexto = document.getElementById('campoTexto');
const contadorCaracteres = document.getElementById('contadorCaracteres');
campoTexto.addEventListener('input', function() {
contadorCaracteres.textContent = `Caracteres ingresados: ${campoTexto.value.length}`;
});
// Ejercicio 3 - Selección única en la lista con delegación de eventos
const listaItems = document.getElementById('listaItems');
listaItems.addEventListener('click', function(event) {
const item = event.target.closest('li');
if (!item || !listaItems.contains(item)) {
return;
}
listaItems.querySelectorAll('li').forEach(function(li) {
li.classList.remove('seleccionado');
});
item.classList.add('seleccionado');
});

View File

@@ -3,3 +3,21 @@ div {
padding: 10px;
margin: 10px;
}
#listaItems {
list-style: none;
padding: 0;
}
#listaItems li {
cursor: pointer;
padding: 6px;
margin: 4px 0;
border: 1px solid #8a8a8a;
}
#listaItems li.seleccionado {
background-color: #7daa3c;
color: #ffffff;
}

View File

@@ -9,19 +9,32 @@
<body>
<h1>Clase 9 - Eventos</h1>
<div id="ejercicio-1">
<!-- Agregar acá el código HTML que haga falta para el ejercicio 1 -->
<button id="miBoton">Hacer clic</button>
<p id="contadorClicks">Botón clickeado 0 veces</p>
</div>
<hr>
<div id="ejercicio-2">
<!-- Agregar acá el código HTML que haga falta para el ejercicio 2 -->
<label for="campoTexto">Escribe algo:</label>
<input type="text" id="campoTexto" />
<p id="contadorCaracteres">Caracteres ingresados: 0</p>
</div>
<hr>
<div id="ejercicio-3">
<!-- Agregar acá el código HTML que haga falta para el ejercicio 3 -->
<ul id="listaItems">
<li>Ítem 1</li>
<li>Ítem 2</li>
<li>Ítem 3</li>
<li>Ítem 4</li>
<li>Ítem 5</li>
</ul>
</div>
<hr>
<div id="ejercicio-4">
<!-- Agregar acá el código HTML que haga falta para el ejercicio 4 -->
<div id="externo">
<div id="interno">
<button id="botonCaptura">Click</button>
</div>
</div>
</div>
<hr>
<div id="ejercicio-5">