IE ignores added onclick attribute

Posted by user357034 on Stack Overflow See other posts from Stack Overflow or by user357034
Published on 2010-06-17T04:20:16Z Indexed on 2010/06/17 4:23 UTC
Read the original article Hit count: 218

Filed under:
|

The Jquery code below works ok with firefox, Safari, Opera but not with IE. I kinda know why this isn't working in IE after reading a lot about it but I do not know how to fix it. My understanding (I think) is that this method will assign a attribute of "onclick" in IE rather than an event method. Therefore it will not fire in IE and the href fires instead which in this case is "#" which is exactly what is happening. What is the correct way of adding the onclick event.

<a id="product_photo_zoom_url" href="/PhotoGallery.asp?ProductCode=9857%2D116%2D003"  
title="9857-116-003 Ignition box"><img id="product_photo" 
src="/v/vspfiles/photos/9857-116-003-2T.jpg" border="0"
alt="9857-116-003 Ignition box" /></a> <br /><a id="product_photo_zoom_url2"  href="/PhotoGallery.asp?ProductCode=9857%2D116%2D003"
title="9857-116-003 Ignition box">
<img src="/v/vspfiles/templates/100/images/buttons/btn_largerphoto.gif" border="0"></a>





var global_URL_Encode_Current_ProductCode;
var global_Config_ProductPhotosFolder;
var global_Current_ProductCode;

var titleattr = $("a#product_photo_zoom_url").attr("title"); 
var picurl='tb_show(titleattr, \'/PhotoDetails.asp?ShowDESC=N&ProductCode=\' + global_URL_Encode_Current_ProductCode + \'&TB_iframe=true&height=600&width=520\');return false;'

$("a#product_photo_zoom_url").attr('onclick', picurl);
$("a#product_photo_zoom_url").attr('href', '#');

$("a#product_photo_zoom_url2").attr('onclick', picurl);
$("a#product_photo_zoom_url2").attr('href', '#');

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery