{"id":27,"date":"2007-10-21T23:44:29","date_gmt":"2007-10-21T20:44:29","guid":{"rendered":"http:\/\/www.held.org.il\/blog\/?p=27"},"modified":"2007-10-21T23:44:29","modified_gmt":"2007-10-21T20:44:29","slug":"onmouseout-event-of-a-container-div","status":"publish","type":"post","link":"http:\/\/www.held.org.il\/blog\/2007\/10\/onmouseout-event-of-a-container-div\/","title":{"rendered":"&#039;onmouseout&#039; event of a container div"},"content":{"rendered":"<p>Today I wanted to catch a 'mouse-out' event in a div. Every time the mouse leaves the div, I want to call a function So.. there's the <a href=\"http:\/\/www.w3schools.com\/jsref\/jsref_onmouseout.asp\">onmouseout<\/a> event which, at first sight, does exactly what I needed.<br \/>\n<code><br \/>\n<span style=\"color: #808080;\"> &lt;div id=\"parent\" style=\"height: 500px; width: 500px;\" onmouseout=\"alert('out!');\"&gt;<br \/>\n&lt;table id=\"child\"&gt;&lt;tr&gt;&lt;td&gt;child text&lt;\/td&gt;&lt;\/tr&gt;<br \/>\n&lt;\/div&gt;<\/span><br \/>\n<\/code><\/p>\n<p>HOWEVER - if the <em>div<\/em> contains child elements (it usually does.. like above example), when mouse moves from the \"bare naked\" <em>div<\/em> directly to its child element, an 'onmouseout' event is called from the <em>div<\/em>, while the mouse is still inside the borders of the <em>div<\/em>. And the worst news is that it's not a bug! \ud83d\ude42<\/p>\n<p>So straight to the sad solution: <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms536946.aspx\"><strong><em>onmouseleave<\/em><\/strong><\/a> event does exactly what I needed, but isn't standard and is IE-only (same goes for <em><a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ms536945.aspx\">onmouseenter<\/a>)<\/em>. As Rick summed it in the <a href=\"http:\/\/www.west-wind.com\/WebLog\/posts\/5215.aspx\">post which solved my issue today<\/a>: \"Bummer.\"<\/p>\n<p>So bummer, but the good thing is that among the reads, I've found this must-read article which talks about <a href=\"http:\/\/www.quirksmode.org\/js\/events_order.html\">the order browsers handle the events<\/a>, and how to deal with it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I wanted to catch a &#8216;mouse-out&#8217; event in a div. Every time the mouse leaves the div, I want to call a function So.. there&#8217;s the onmouseout event which, at first sight, does exactly what I needed. &lt;div id=&#8221;parent&#8221; style=&#8221;height: 500px; width: 500px;&#8221; onmouseout=&#8221;alert(&#8216;out!&#8217;);&#8221;&gt; &lt;table id=&#8221;child&#8221;&gt;&lt;tr&gt;&lt;td&gt;child text&lt;\/td&gt;&lt;\/tr&gt; &lt;\/div&gt; HOWEVER &#8211; if the div contains [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[55,66,202],"_links":{"self":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/27"}],"collection":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/comments?post=27"}],"version-history":[{"count":0,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/27\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/media?parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/categories?post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/tags?post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}