Reputation: 125
trying to figure out how to add onclick="location.href='link.html'". so that when the user clicks on image it will take the user to a url. Just not sure how to include this in the code below. Here is my code...
<a class="thumbnail even"
onClick="_gaq.push(['_trackEvent', 'holiday', 'logo', 'jcpenney']);"
onmouseover="changeImgSrc('JCP_FullImage_321x400.png')"
onmouseout="document.getElementById('partnerHoverImg').src='../images/FPO_FullImage_321x400.png'">
<img src="../images/JCPenney_logo_150x110.png"/></a>
Been looking at this for a minute and any help would be greatly appreciated! Thanks!
Upvotes: 0
Views: 2376
Reputation: 92274
You should just add an href="link.html"
to the a tag as others have suggested.
If you can't do that and you can't add another handler with JavaScript, you just need to add another statement within the onclick
attribute
<a class="thumbnail even"
onclick="_gaq.push(['_trackEvent', 'holiday', 'logo', 'jcpenney']);
location.href='link.html'"
onmouseover="changeImgSrc('JCP_FullImage_321x400.png')"
onmouseout="document.getElementById('partnerHoverImg').src =
'../images/FPO_FullImage_321x400.png'"
>
<img src="../images/JCPenney_logo_150x110.png"/>
</a>
Upvotes: 0
Reputation: 3034
You already have it wrapped in a link. Just set the href:
<a href="PUT YOUR LINK HERE" class="thumbnail even" onClick="_gaq.push(['_trackEvent', 'holiday', 'logo', 'jcpenney']);" onmouseover="changeImgSrc('JCP_FullImage_321x400.png')" onmouseout="document.getElementById('partnerHoverImg').src='../images/FPO_FullImage_321x400.png'"><img src="../images/JCPenney_logo_150x110.png"/></a>
Please separate your UI from your functionality. It iwll make your code a lot more readable and easier to maintain. That said, you could stick the link in a data attribute inside the img - something like this:
<img class="RedirectImage" data-url="www.google.com" src="blah.jpg"/>
JQuery:
$(".RedirectImage").click(function(e){
document.location.href = $(this).data("url");
});
Upvotes: 1