forked from marquez.juan/clase-8-DOM
feat: add buildList function to create a list from an array of items
This commit is contained in:
@@ -76,3 +76,25 @@ const changeImage = () => {
|
|||||||
const image = document.querySelector('img');
|
const image = document.querySelector('img');
|
||||||
image.src = "foto2.jpg";
|
image.src = "foto2.jpg";
|
||||||
image.alt = 'Locro';}
|
image.alt = 'Locro';}
|
||||||
|
|
||||||
|
// Ejercicio 8
|
||||||
|
|
||||||
|
const buildList = (arr) => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.classList.add('grupo-comidas');
|
||||||
|
|
||||||
|
const h2 = document.createElement('h2');
|
||||||
|
h2.textContent = arr[0];
|
||||||
|
div.appendChild(h2);
|
||||||
|
|
||||||
|
const ul = document.createElement('ul');
|
||||||
|
|
||||||
|
for (let i = 1; i < arr.length; i++) {
|
||||||
|
const li = document.createElement('li');
|
||||||
|
li.textContent = arr[i];
|
||||||
|
ul.appendChild(li);
|
||||||
|
}
|
||||||
|
|
||||||
|
div.appendChild(ul);
|
||||||
|
return div;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user