views:

353

answers:

1

Trying to accses the class name from the event.target object. Works in FF, Safari, and Chrome. InternetExplorer 7 alerts "undefined". Any suggestions?

<script type="text/javascript">
 $("document").ready(function(){ 
  $(".page").hide();
  $(".page:first").show();
  $("#navBar a").bind("click", linkClicked);
 });
 function linkClicked(event){
   $("div.page:visible").fadeOut(250, function(){
    var $target = $(event.target);
    alert($target.attr("class"));
    //$("#" + $(event.target).attr("class")).fadeIn(250);
   }); 
 }
</script>
+1  A: 

Found a solution. Set the event.target to a var before the callback for fade out. :p any idea why?

<script type="text/javascript">
 $("document").ready(function(){ 
  $("#content").css("opacity","0.8");
  $(".page").hide();
  $(".page:first").show();
  $("#navBar a").bind("click", linkClicked);
 });
 function linkClicked(event){
  var $target = $(event.target);
  $("div.page:visible").fadeOut(250, function(){
   alert($target.attr("class"));
   //$("#" + $(event.target).attr("class")).fadeIn(250);
 });    
 }
</script>
Drock
My guess, once the fading animation starts, the IE7's DOM event handling screwed up (at least temporarily), hence it can't return the 'target' it is 'animating' then. Glad you found a work-a-round. Btw, do accept your own answer :P
o.k.w