I have some JSON data and I would like to get the image from it and put it into a div somehow, I have tried the following code but it does not work.
JSON
var data={"articles":
[
{
"id": 1,
"title": "Lorem Ipsum is simply dummy",
"sub": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text.",
"auth": "Latin text",
"image": "http://placehold.it/350x150"
},
{
"id": 2,
"title": "Lorem Ipsum is simply dummy",
"sub": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text.",
"auth": "Latin text",
"image": "http://placehold.it/350x150"
},
{
"id": 3,
"title": "Lorem Ipsum is simply dummy",
"sub": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text.",
"auth": "Latin text",
"image": "http://placehold.it/350x150"
},
{
"id": 4,
"title": "Lorem Ipsum is simply dummy",
"sub": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text.",
"auth": "Latin text",
"image": "http://placehold.it/350x150"
}
]}
JAVASCRIPT
data.articles.forEach( function(obj) {
var img = new Image();
img.src = obj.image_url;
document.getElementById("image_url_1").innerHTML=data.articles[1].image_url;
});
HTML (images go into separate div ids as follows:
<div id="image_url_1"></div>
<div id="image_url_2"></div>
The images will need to go in separate div ids. I don't know what I am doing wrong?
obj.image_url?