I'm trying to get the values based on the id of elements in HTML. How can I get it from the JSON array? My JSON file looks like this:
[
{
"product": "gill",
"link": "x.com",
"thumbnail": "gill.jpg"
},
{
"product": "folded",
"link": "y.com",
"thumbnail": "folded.jpg"
}
]
and my JS file looks like:
window.onload = function (){
const apiUri = "./test.json";
const urun = document.getElementById("products");
const search = document.getElementById("products").children[0].id;
fetch(apiUri)
.then(response => response.json())
.then(data => {
const Link = document.createElement("a");
const Image = document.createElement("img");
Link.setAttribute("href", data.link);
Image.setAttribute("src", data.thumbnail);
urun.append(Link);
Link.append(Image);
Link.classList.add(element.product);
})
}
What I want to do is, if const search = gill, get the thumbnail value of gill from JSON, if const search = folded, get the thumbnail value of folded from JSON.
Could you please lead me the right way?