0
var loadingImage = image.src(data.points_of_interest[i].main_image);
var bodystuff = document.createElement('img');
bodystuff.innerHTML = loadingImage,
bodystuff.innerHTML = loadingImage,
document.getElementById('outputs').appendChild(bodystuff);

That is my Javascript above and here is my HTML;

<section id="outputs">    
</section>

The image location from the API response is located here; data.points_of_interest[i].main_image

(do note it is in URL format = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/Westminster_Abbey_West_Door.jpg/337px-Westminster_Abbey_West_Door.jpg")

(also it is in a loop hence the use of [i]);

any pointers, please?

My above code only prints out the URL in the console.

Thanks

2

1 Answer 1

1

Try this:

var src = data.points_of_interest[i].main_image; // URL of the image
var bodystuff = document.createElement('img');
bodystuff.src=src;
document.getElementById('outputs').appendChild(bodystuff);
Sign up to request clarification or add additional context in comments.

1 Comment

Worked fine; however I'm now stuck in a situation where I am trying to print out another information e.g data.point_of_interest[i].title, at the same time as printing the image above so that I can style them both; I have tried appending the variable given to the title to the image but nothing works? any pointers? @SandeepNayak

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.