I’m trying to dynamically load data for my cards using javascript and JSON.
Everything works fine, loading the titles, descriptions & so on.
Now I’m having this issue where I try to dynamically add a separate link for each card
(which doesn’t seems to work as I thought it would.)
This is my html :
<div class="navbar__container"></div>
This is the javascript I used to make it work :
let http = new XMLHttpRequest();
http.open('get', 'products.json', true);
http.send();
http.onload = function () {
if (this.readyState == 4 && this.status == 200) {
let products = JSON.parse(this.responseText);
let output = "";
for (let item of products) {
output += `
<div class="product">
<img class="products__img" src="${item.image}" alt="${item.description}">
<p class="products__title">${item.title}</p>
<a href="${item.link}" class="products__link">Check it out!</a>
<p class="products__usedTechnologies">USED TECHNOLOGIES</p>
<p class="products__description">${item.description}</p>
</div>
`;
}
document.querySelector(".products").innerHTML = output;
}
}
This is the JSON-File :
{
"image": "json-images/exampleImg.png",
"title": "This is an example",
"description": "html, css, javascript, three.js, webGL, node.js",
"link": "href=https://bitcoin.org/nl/"
},
To make things clear, everything works except the dynamically loading of the link from the json-file, I feel the problem is based on how I call the “href” in the javascript file.
See screenshot of how it looks like:
The error I get when clicking the link:
Normally I’m quite fast on how to figure out things like this but this has been something that I can’t seem to fix, all help is appreciated