views:

60

answers:

2

as follow codes:

<div id="outerBox" style="border:1px solid red;width:300;height:300" onmouseout="alert('out')">
<div id="innerBox" style="border:1px solid blue;width:50;height:50">inner</div>
</div>

why when i move mouse on the "innerBox", it was trigger alert('out') ?

i want mouse out "outerBox" trigger alert('out') only, mouse on "innerBox" don't trigger alert.

hot to do this?

thanks all :)

+2  A: 

I found something here which looks as the function you need: http://codingrecipes.com/onmouseout-fix-on-nested-elements-javascript

Kau-Boy
Looks promising
Kaaviar
it's great!thank you
Zenofo
Glad I could help you. But why no up vote? :)
Kau-Boy
+4  A: 

This is the standard behaviour for the mouseout and mouseover events. Internet Explorer actually one-ups the competition here (for a change), because it has proprietary events that provide the behaviour that you're looking for; onmouseenter and onmouseleave. The major downside is that these events aren't part of the standard and other browsers haven't implemented them.

If you use jQuery, it has a nice cross-browser implementation with .mouseleave(). It's a good idea to use a framework to handle cross-browser events for you anyway. It doesn't have to be jQuery, but I'm not sure if the others have a mouseleave event.

If you're not using jQuery or a framework that provides the simulated event, see http://ecmascript.stchur.com/2007/03/15/mouseenter-and-mouseleave-events-for-firefox-and-other-non-ie-browsers/

Andy E
Prototype also has simulated `mouseenter` and `mouseleave`, FWIW
T.J. Crowder
@T.J. Thanks, I'll remember that. I didn't really know which other frameworks had it. I do know that [quirksmode.org](http://www.quirksmode.org/dom/events/mouseover.html#t10) has been ranting about the events not being supported in other browsers for a while, with not much success :-)
Andy E
@Andy E's head: Yeah, kind of surprising, especially given how easy it is to do it! Even Chrome doesn't have them natively.
T.J. Crowder