1

i want to run a script when i'm not hovering an element. It's some kind of deactivating something else that was run previously in 'onmouseover' event. So I'm using onmouseout event to run this script, however , the problem is that if i don't hover the element and then leave it , the script just don't run. this happens if e.g hover the element too fast or the window loses focus . How can i solve that?

EDIT: let me illustrate this in another way , what i need is an event to be run when an element isn't touched by mouse.

2 Answers2

2

you can try this,

<div id="div1" onmouseover="fucntionIn()" onmouseout="functionOut()">"Special Area"</div>
<div id="div2" onmouseover="fucntionOut()">Other area</div>

the logic is to write deactivate code for onmouseover event of other area of the page.

Lasantha Bandara
  • 809
  • 3
  • 10
  • 22
1

What if you detect onmouseover on the whole page (through event bubbling), and when it enters a new element find if the original element that you last observed is a parent of the current target element, if it is not then you know it exited the original DOM node, even if onmouseout did not fire.

Matt
  • 41,216
  • 30
  • 109
  • 147
  • I don't think the browser will ever forget to fire the `onmouseout` event after `onmouseover` is triggered – John Dvorak Nov 01 '12 at 19:51
  • 1
    @JanDvorak while I would like to think so, I've seen similar expectations shattered when altering the DOM is involved. While that doesn't seem like the case here, it should be noted that such assumptions are not always valid (see http://stackoverflow.com/questions/2732818/if-you-delete-a-dom-element-do-any-events-that-started-with-that-element-contin) – Matt Nov 01 '12 at 19:53
  • Interesting link. I shouldn't be surprised IE did something wrong ;-) – John Dvorak Nov 01 '12 at 19:58