0

this is my code:

function riep() {
    imuno = sessionStorage.getItem('imuno');
    imdue = sessionStorage.getItem('imdue');
    document.getElementById("myDiv").innerHTML = imuno + ", " + imdue;
}

It displays the src contained in the two variables (imuno,imdue) instead of the images, how can i solve that?

3
  • 3
    use <img> tags for images Commented Feb 29, 2016 at 13:36
  • 1
    use an <img > tag and set it's src Commented Feb 29, 2016 at 13:36
  • 1
    document.getElementById("myDiv").innerHTML is used to show the content in the element. Also, from the names, it looks like you're using <div> element. Use <img> and set the src attribute value. document.getElementById('imgId').src = 'Happy'; Commented Feb 29, 2016 at 13:36

2 Answers 2

2
function riep() {
    imuno = sessionStorage.getItem('imuno');
    imdue = sessionStorage.getItem('imdue');
    document.getElementById("myDiv").innerHTML = "<img src='" + imuno + "'/><img src='" + imdue + "'/>";
}
Sign up to request clarification or add additional context in comments.

2 Comments

It works perfecly! Thank you very much and thanks everyone for replying!
Just another question, how can i change the images size with css? I mean, where should i link the js or html to my css page?
1
<img src="..." class="image" />

You can use:

<img src="..." class="image" width=150 height=150 />

or

<img src="..." class="image" style="width: 150px; height: 150px;" />

or

you can add style tag to html like:

<style>
    .image {
        width: 150px;
        height: 150px;
    }
</style>

or

you can add link tag to your html with styles like:

<link rel="stylesheet" type="text/css" href="styles.css" />

and so on :)

1 Comment

Thank you again, reeeally helpful :)

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.