This commit is contained in:
szabomarton
2024-11-08 08:43:27 +01:00
parent 8d899f9d76
commit b7305d2c2b
4 changed files with 95 additions and 0 deletions

27
24_11_08/feladat1.js Normal file
View File

@@ -0,0 +1,27 @@
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);
}