-4

I have image URL's in a js file as objects.

How do I grab those images and insert them into the HTML dynamically?

I have tried using id's and getElementById but that didn't work.

3

1 Answer 1

-1

Fixed HTML (switched classes and IDs to make IDs unique) and added an image ID for simplicity:

<div id="msgStyle1" class="message">Waiting for image</div> <div id="imgStyle1" class="message"> <img src="" id="image" /> </div>

JS:

document.getElementById('image').src = 'http://yourImagePathHere';

See it work here: http://jsfiddle.net/N3rCm/

Sign up to request clarification or add additional context in comments.

1 Comment

This worked perfect, thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.