forked from marquez.juan/clase-8-DOM
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
// Vincular este archivo al archivo index.html, y resolver aquí los ejercicios.
|
|
//Ejercicio 1
|
|
function cambiarTitulo() {
|
|
const titulo = document.querySelector("h1");
|
|
|
|
titulo.textContent = "Nuevo título de la página";
|
|
}
|
|
|
|
//Ejercicio 2
|
|
|
|
function agregarClaseLista() {
|
|
const items = document.querySelectorAll("li");
|
|
|
|
for (const item of items) {
|
|
item.classList.add("item-lista");
|
|
}
|
|
}
|
|
|
|
//Ejercicio 3
|
|
function agregarItem(texto) {
|
|
const lista = document.querySelector("#lista-inicial");
|
|
|
|
const nuevoItem = document.createElement("li");
|
|
|
|
nuevoItem.textContent = texto;
|
|
|
|
lista.appendChild(nuevoItem);
|
|
}
|
|
|
|
//Ejercicio 4
|
|
function destacarParrafos() {
|
|
const parrafos = document.querySelectorAll("#parrafos p");
|
|
|
|
for (const parrafo of parrafos) {
|
|
if (parrafo.textContent.includes("importante")) {
|
|
parrafo.classList.add("destacado");
|
|
}
|
|
}
|
|
}
|
|
|
|
//Ejercicio 5
|
|
function agregarComidasLitoral() {
|
|
const div = document.createElement("div");
|
|
|
|
const titulo = document.createElement("h2");
|
|
titulo.textContent = "Comidas típicas del litoral";
|
|
|
|
const parrafo = document.createElement("p");
|
|
parrafo.textContent = "Algunas comidas tradicionales de la región.";
|
|
|
|
const lista = document.createElement("ul");
|
|
|
|
const comidas = ["Chipá", "Pacú", "Mbejú"];
|
|
|
|
for (const comida of comidas) {
|
|
const item = document.createElement("li");
|
|
|
|
item.textContent = comida;
|
|
|
|
lista.appendChild(item);
|
|
}
|
|
|
|
div.appendChild(titulo);
|
|
div.appendChild(parrafo);
|
|
div.appendChild(lista);
|
|
|
|
document.body.appendChild(div);
|
|
} |