Popup not working in IE7 and IE8

Got the following code for a project I’m working on but the JavaScript isnt working in IE7 and IE8

<script type="text/javascript">
var drinks = ['rum', 'le', 'montingo', 'tingquila', 'passionate'];

function openDrink(e) {
  $("div." + e.data).fadeIn("slow");
}

$(document).ready(function() {
  $.each(drinks, function(i, el) {
    $("div." + el + " > img.close").click(function(tar) {
      $(tar.currentTarget).parent().fadeOut("slow");
    });
    $('img.' + el).click(el, openDrink);
  });
});
</script>

anyone know of a fix for this.
thanks in advance :slight_smile:

IE 7 & 8 don’t support the event.currentTarget property so instead you have to use event.srcElement for IE, see the updated code below.

$(tar.currentTarget ? tar.currentTarget : tar.srcElement).parent().fadeOut("slow");

Thank you SgtLegend worked a treat, also good to know for future products!!

Another shortcut for the current element inside a Jquery event handler is $(this) … e.g.


$("#links li a").click(function(){ 
  $(this).parent(); // points to the parent li of the clicked link
});