views:

1033

answers:

3

I have a table inside of a Div, containing 8 images, I want to fire a mouseout event for either the table or the div, but it doesn't fire. I'm guessing this is because the mouse is actually leaving each of the images, or the td, or the tr etc... is there a way to get the mouseout event for the entire table to propagate up so that it is fired even from the child elements? The markup is straight forward:

<div id=container>
  <table id="tbl">
    <tr>
      <td><img src=""></td>
      <td><img src=""></td>
      <td><img src=""></td>
      <td><img src=""></td>
    </tr>
    <tr>
      <td><img src=""></td>
      <td><img src=""></td>
      <td><img src=""></td>
      <td><img src=""></td>
    </tr>
  </table>
</div>

and my jQuery code is:

$("#tbl").mouseout(function(){
  alert("out home");
});

I can't fire the individual mouseout events for the images because there are sometimes absolutely placed elements over them which causes the mouseout event to be fired prematurely.

+1  A: 

Should be:

$("#tbl").mouseout(function(){
  alert("out home");
});

You have missed the "#". If you want only images, try:

$("#tbl >img").mouseout(function(){
  alert("out home");
});

PS. Did you considered to use $( "...").hover( ), instead?

Artem Barger
Hey, sorry.. i'm bad for that! I strip out too much from my actual code, I have the '#' inside of my actual js file... anything else?
Fermin
does the absolutely placed element overlap the table is well?
Artem Barger
I've re-read your post and realized I'm not completely understand, doesn't your code work at all or just partially and what effect you are trying to gain?
Artem Barger
The table is completely filled with the 8 images. The absolutely placed div can partially cover any of the images, so, yes, it overlaps the table also. I want to have a mouseout for the images but when i mouseover the absolutely placed div the img.mouseout fires.. which I don't want. I figured a way round this would be a mouseout for the table but it is not firing at all.Sorry if this is confusing!
Fermin
So for table you have to be sure you completely out of table. Did you check it(try render the border)?
Artem Barger
Yeah I have the table inside a div in the centre of the screen which has borders, and using Firebug I can see that I'm leaving the table and the event isn't fired.
Fermin
A: 

Shouldn't you use #tbl to select the table?

$("#tbl").mouseout(function(){
  alert("out home");
});
gustavlarson
A: 

Use mouseleave event, which has exact same functionality but it doesn't fire with child elements.

$("#tbl").bind("mouseleave",function(){
  alert("out home");
});
Mayur