0

I have div inside a div with the parent div have onmouseover and onmouseout functions

but when I hover on the child div the onmouseout function is triggerd which I don't want help?

<div onmouseover="alert("inside")" onmouseout="alert("outside")> <div></div> </div>

example:

http://jsfiddle.net/sp9bD/2

the black div is inside the red one but the "outside" alert shows up

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    There is called event bubbling. Take a look at this SO question: http://stackoverflow.com/questions/5971601/javascript-event-bubbling – Ye Liu Jun 16 '13 at 19:22

1 Answers1

0
$('div').hover(function(e) {
    if (!(event.target.id === "inside")) {
        alert('inside');
    }
}, function () {
        alert('outside');

});

Try something like this using jQuery, here's the redone fiddle

http://jsfiddle.net/sp9bD/3/

James Daly
  • 1,357
  • 16
  • 26