CaffeinatedCM
CaffeinatedCM

Reputation: 764

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? :)

Upvotes: 6

Views: 12602

Answers (4)

alex
alex

Reputation: 490183

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.

Upvotes: 10

jwerre
jwerre

Reputation: 9584

Try this :

target = (window.event) ? window.event.srcElement /* for IE */ : event.target

Upvotes: 1

samccone
samccone

Reputation: 10926

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

This should work just fine

Upvotes: 0

CrayonViolent
CrayonViolent

Reputation: 32532

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

Upvotes: 1

Related Questions