I am trying to print out the API response data in the DOM. As you can see, I am able to get a response based on the user input. I am able to print the response out to the console, but I am confused why the code below won't print out the same information in the DOM.
if (containsItem == "1") {
const proxyUrl = "https://cors-anywhere.herokuapp.com/",
targetUrl =
"http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=";
fetch(proxyUrl + targetUrl + i)
.then((data) => data.json())
.then(({ item: { id, name, current: { price } } }) =>
console.log(`${id}: ${name} ${price}`)
);
document.getElementById("itemData").innerHTML = `${id}: ${name} ${price}`;
} else {
document.getElementById("alert").style.display = "block";
setTimeout(function() {
$("#alert").fadeOut("slow");
}, 2500);
}
I would really appreciate some help and better understanding of what I am doing wrong. Thank you in advance.