Closed MohamadAlGhorani closed 4 years ago
ik zie dat je ongeveer dezelfde code gebruikt twee keer.
console.log(jsonData.data.results[1]); for (const comic of jsonData.data.results) { console.log(comic); const section = document.querySelector('.series'); const article = document.createElement('article'); const heading = document.createElement('h2'); const articleImage = document.createElement('img'); heading.textContent = `${comic.title}`; //template literals articleImage.src = `${comic.thumbnail.path}.${comic.thumbnail.extension}`; article.appendChild(articleImage); article.appendChild(heading); section.appendChild(article); }
je kunt deze gedeelte in een functie neer zetten en hergebruiken bij elke fetch()
fetch()
function renderHtml (parent){} deze functie krijgt een parent mee als parameter zodat je het data kan toevoegen aan verschillende
Thanks for the tip! And already fixed.
ik zie dat je ongeveer dezelfde code gebruikt twee keer.
je kunt deze gedeelte in een functie neer zetten en hergebruiken bij elke
fetch()
voorbeeld
function renderHtml (parent){} deze functie krijgt een parent mee als parameter zodat je het data kan toevoegen aan verschillende