ejercicio2
This commit is contained in:
@@ -1 +1,21 @@
|
||||
// Agregar aquí el código javascript
|
||||
|
||||
// Crear una página con un campo de texto y un botón "Agregar". Cada vez que se
|
||||
// haga clic en el botón, agregar el texto del campo como un nuevo ítem en una
|
||||
// lista `<ul>`. Después de agregar el ítem, limpiar el campo.
|
||||
|
||||
// Si el campo está vacío al hacer clic, no agregar nada.
|
||||
|
||||
let input = document.querySelector("input") //almacenamos en variables el boton, el input y la lista
|
||||
let boton = document.querySelector("button");
|
||||
let lista = document.querySelector("ul")
|
||||
|
||||
boton.addEventListener("click", ()=>{ // creamos el listener "click" con la funcion
|
||||
if (!(input.value.trim() === "")){ // si el input NO ESTÁ vacio, continuamos :
|
||||
nuevoLi = document.createElement("li"); //creamos el li ,
|
||||
nuevoLi.textContent = input.value.trim(); // le damos contenido ,
|
||||
lista.appendChild(nuevoLi); // lo anexamos a la lista ,
|
||||
input.value = ""; // y vaciamos el input :)
|
||||
}
|
||||
})
|
||||
// fin
|
||||
Reference in New Issue
Block a user