Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery event.target not working in firefox and IE?

I'm working on making an image slider that loads the image the user clicks on using jQuery. I have it working great in Chrome but when I tried it in firefox and IE it's not loading the image at all. Here's my code:

    $("img.clickable").click( function() {
    $("#image_slider").animate({opacity:1.0,left:200},"slow");
    $("#image_container").attr("src",event.target.src);
    ihidden = false;
});

When I try running this in firefox or IE it just doesn't load the image at all. Any ideas? :)

like image 635
CaffeinatedCM Avatar asked May 01 '11 04:05

CaffeinatedCM


2 Answers

You need to define the event in the arguments.

$("img.clickable").click( function(event) {
    $("#image_slider").animate({opacity:1.0,left:200},"slow");
    $("#image_container").attr("src",event.target.src);
    ihidden = false;
});

Otherwise it is going to use window.event.

like image 186
alex Avatar answered Nov 13 '22 16:11

alex


try using $(this).attr('src') instead of event.target.src

like image 23
Crayon Violent Avatar answered Nov 13 '22 18:11

Crayon Violent