forked from marquez.juan/clase-8-DOM
80 lines
1.9 KiB
JavaScript
80 lines
1.9 KiB
JavaScript
// Vincular este archivo al archivo index.html, y resolver aquí los ejercicios.
|
|
function cambiarText(texto){
|
|
const textoH1 = document.querySelector("h1");
|
|
textoH1.textContent = texto;
|
|
}
|
|
|
|
function agregarClase(){
|
|
const listaComida = document.querySelectorAll(".item-comida");
|
|
for (const i of listaComida){
|
|
i.classList.add("item-lista");
|
|
}
|
|
}
|
|
|
|
function agregarItem(texto){
|
|
const lista = document.querySelector("#lista-inicial");
|
|
const nuevo = document.createElement("li");
|
|
|
|
nuevo.textContent = texto;
|
|
|
|
lista.appendChild(nuevo);
|
|
|
|
}
|
|
|
|
function destacarImportantes() {
|
|
const parrafos = document.querySelectorAll("#parrafos p");
|
|
|
|
for (const p of parrafos) {
|
|
if (p.textContent.includes("importante")) {
|
|
p.classList.add("destacado");
|
|
}
|
|
}
|
|
}
|
|
|
|
function agregarComidasLitoral() {
|
|
|
|
const contenedor = document.createElement("div");
|
|
|
|
const titulo = document.createElement("h2");
|
|
titulo.textContent = "Comidas típicas del litoral";
|
|
|
|
const parrafo = document.createElement("p");
|
|
parrafo.textContent = "Comidas tradicionales de la región";
|
|
|
|
const lista = document.createElement("ul");
|
|
|
|
const comidas = [
|
|
"Chipá",
|
|
"Surubí",
|
|
"Pacú",
|
|
"Empanadas de pescado",
|
|
"Mbejú"
|
|
];
|
|
|
|
for (const comida of comidas) {
|
|
const item = document.createElement("li");
|
|
item.textContent = comida;
|
|
lista.appendChild(item);
|
|
}
|
|
|
|
contenedor.appendChild(titulo);
|
|
contenedor.appendChild(parrafo);
|
|
contenedor.appendChild(lista);
|
|
|
|
document.body.appendChild(contenedor);
|
|
}
|
|
|
|
function limpiarLista(idLista){
|
|
|
|
const items = document.querySelectorAll(`#${idLista} li`);
|
|
|
|
for (const item of items){
|
|
item.remove();
|
|
}
|
|
}
|
|
|
|
function cambiarFoto(foto, texto){
|
|
const imagen = document.querySelector("#foto");
|
|
imagen.setAttribute("src", foto);
|
|
imagen.setAttribute("alt", texto);
|
|
} |