ArK
ArK

Reputation: 21066

cancel mouse events

i'm using a mouse event for an outer element. how to cancel the from triggering by sub elements with reasonably small code

  <div onmouseout='myfunc()'>
     <div>item1</div>
     <div>item2</div>
     ...............
     <div>item n</div>
  </div>

mouseevent should not apply to item1 to n

Upvotes: 0

Views: 2762

Answers (2)

kennebec
kennebec

Reputation: 104840

You can set up myfunc to only recognize the element the mouse event was set on-

function myfunc(e){
  var who=window.event? event.srcElement || e.target;
  if(who.onmouseout==arguments.callee){
    // whatever
  }
}

Upvotes: 2

Vlad Andersen
Vlad Andersen

Reputation: 366

The mouseout event fires when you are leaving the parent element and entering child elements. In order to treat the all the child elements as a single block with the parent element, you case use the mouseleave event: in native JS it's for IE only, but there is a cross-browser implementation in jQuery.

Upvotes: 1

Related Questions