0

HTML equivalent:

<a href='#'> <img src='...'....../></a>

Looking for something along the lines of:

var im = document.createElement("img");
im.ADDLINK;

Relevant code:

var close = document.createElement("img");
    close.src="close.png";
    close.width = 50;
    close.height = 50;
    close.border = 1;
    close.className="closeButton";
    close.style.cssFloat="right";

    var link = document.createElement("a");
    link.href = "#";

Make close image a link:

    link.appendChild(close);

    close.style.right=0+"px";
            //Div img is a div created above this code snippet:
    divimg.appendChild(close);
1
  • You insert the image to a link element but then you insert only the image to the div. Change the last line to divimg.appendChild(link); Commented Mar 11, 2014 at 23:44

2 Answers 2

3

Create the link:

var link = document.createElement(a);
link.href = "http://...com";

Add the image:

var im = document.createElement("img");
link.appendChild(im);

And append it to the DOM where needed

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

1 Comment

Thanks tymeJV, still doesn't work for me though. I'll add code snippet above.
0

You can try this

<script>
   function imgRedirect(destination){

     location.href = destination;

   }
</script>
<img src="..." onclick="imgRedirect('http://google.com')"/>

2 Comments

What does this have to do with the question?
Thanks for the reply cris_dpa, unfortunately it all needs to be done via javascript.

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.