Reputation: 381
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);
Upvotes: 0
Views: 2818
Reputation: 346
You can try this
<script>
function imgRedirect(destination){
location.href = destination;
}
</script>
<img src="..." onclick="imgRedirect('http://google.com')"/>
Upvotes: 0
Reputation: 104775
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
Upvotes: 3