title: MouseOver/MouseOut EventListener inheriting to child nodes?
body: <p><strong>Edit: Solution</strong></p>
  
  <p>Thanks to <a href="https://stackoverflow.com/users/128165/gaby-aka-g-petrioli" title="Gaby">Gaby</a> for the help in finding a solution! Didn't quite work exactly how I wanted it to, found a better solution modified from the answers. What I do is only execute the mouseover/mouseout functions when the two elements (target and related target) <strong>do not share a parent</strong>.</p>
  
  <p>Just modified Gaby's example a bit and have everything working great. As long as your popup is within the same div element as whatever spawns it (even if it's outside the main contents you can append it with overflow visible) and you don't go between non-shared elements on the way over to it, it'll stay alive.</p>
  
  <pre><code>divContents.addEventListener('mouseover', mouseEnter(showPopup, divContents));
  divContents.addEventListener('mouseout', mouseEnter(hidePopup, divContents));
  </code></pre>
  
  <p>Now, the modified mouseEnter...</p>
  
  <pre><code>function mouseEnter(_fn, _parent) {
      return function(_evt) {
          if(!shareParent(_evt.target, _evt.relatedTarget, _parent)) {
              _fn.call(this, _evt);  
          }
      }
  };
  
  function shareParent(_object1, _object2, _parent) {
      if (_object1 === _object2) { 
          return true;
      }
      while (_object1 &amp;&amp; _object1 !== _parent) {
          _object1 = _object1.parentNode;
      }
      while (_object2 &amp;&amp; _object2 !== _parent) {
          _object2 = _object2.parentNode;
      }
  
      return _object1 === _object2;
  }
  </code></pre>
  
  <p>Solved my problem A-OK, because what I want to fire for mouseover and mouseout events will only happen when the elements don't share a parent - exactly how I intended on displaying the popups anyhow.</p>
  
  <p>Thanks again for the code example from Gaby, though!</p>
  
  <p><strong>NOTE:</strong> No error checking for parent validity in shareParent function, haven't checked but it should always return true when it gets to the top of the tree (assuming the _parent isn't actually a parent of either _object1 or _object2). So make sure the parent object you pass to it is valid.</p>
  
  <p><strong>Original Question:</strong></p>
  
  <p>I'm having a problem in JavaScript right now.</p>
  
  <p>I'm trying to create a div Element that pops up dynamically when something has a mouseover. The div is created directly adjacent to the object that spawns it.</p>
  
  <pre><code>divCreator.addEventListener('mouseover', createPopup, true);
  divCreator.addEventListener('mouseout', hidePopup, true);
  </code></pre>
  
  <p>That creates the popup. Now, in the popup, when I create it, I run this before I append it to the document:</p>
  
  <pre><code>divPopup.addEventListener('mouseover', createPopup, true);
  divPopup.addEventListener('mouseout', hidePopup, true);
  </code></pre>
  
  <p>This ensures that if I mouseover the popup, it keeps it alive (because the divCreator mouseout will fire) and when I mouseout of the popup it disappears.</p>
  
  <p>However, with this method, whenever I mouseover a child element it detects a mouseout event from the parent element (divPopup) and closes the div.</p>
  
  <p>Can I make the children 'transparent' to Events, so-to-speak?</p>