0

Javascript Code

    function load()
    {
        var s = window.location.href;
        var temp_img_url=s.split("?");
        var img_url=temp_img_url[1];


    }

html code

 <img id="bigpic" src=" " style="display: none; ">

I am trying to put img_url in src. What is the way to do that. Thank you.

2 Answers 2

7

add this line at the end of your load() function:

document.getElementById('bigpic').src=img_url;

this is from memory (my js is a little rusty) but should do the trick.

It uses the getElementById() method to get the element with the ID of bigpic (your image element) and sets the src attribute to the value of your img_url variable.

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

Comments

0

First you have to find the element:

element = document.getElementById("bigpic");

Then you can change the src attribute of that element:

element.setAttribute("src", img_url);

Comments

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.