Frontend/24_11_08/feladat1.js

27 lines
752 B
JavaScript
Raw Normal View History

2024-11-08 07:43:27 +00:00
let url = "https://jsonplaceholder.typicode.com/photos";
async function fetchAdatok(apiUrl){
try{
let response = await fetch(apiUrl);
let data = await response.json();
data.forEach(element => {
console.log(element);
JsonElementToDomElement(element);
});
} catch (error){
console.log(error);
alert("Hiba Történt!");
}
}
fetchAdatok(url);
let mainDomElement = document.getElementById("appendHere");
async function JsonElementToDomElement(element){
let newDomElement = document.createElement("div");
newDomElement.innerHTML = `${element.title}`;
newDomElement.innerHTML += `<img src="${element.url}">`;
mainDomElement.appendChild(newDomElement);
}