JavaScript onmouseout fires inside the element it's set to

I am currently switching the menu of my site from pure JavaScript to jQuery. My menu has a rollout / rollin effect.

The menu has an outer wrapper which has an onmouseout event set. If this fires, the relatedTarget is checked whether it's a child of the outer wrapper. If not, the rollin shall happen.

What happens right now is, that if the mouse is moved from the menu's inner wrapper (this is to center the actual menu) to the menu's outer wrapper, the onmouseout fires. There seems to be a tiny part which doesn't belong to the menuOuterWrapper.

The site isn't online right now, so I've prepared a Fiddle here. You will see the problem if you move your mouse from the gray area above the handle to the left or right dark area. The menu will roll in and then immediately out again. The rollin shall only occur when the mouse is moved out of the outer wrapper, i.e. under the dark gray area (or the light gray handle area). To see the dark gray areas, you might have to increase the width of the result block. [EDIT: I reduced the width of inner to 600px, so the dark side areas should be visible by default now.]

SO tells me that I shall include code when linking to JSFiddle. I don't want to break the rules but I'll be honest: I'm clueless where the problem comes from. My best idea is that I made a mistake in my isChildOf implementation, so I'll give you this:

jQuery.fn.isChildOf = function (parentId) {
    if ($(this).parents("#" + parentId).length > 0) {
      return true;
    } else {
      return false;
    }
};

$('#outer').on('mouseout', function(event) {
    if (!$(event.relatedTarget).isChildOf("outer")) {
        mouseIsOverMenu = false;
        menu_rollin();
    }
});

Although this is a minimal example, I did nearly the same with pure JS, where it worked fine. So I guess it's something in the jQuery part. Since these are my first steps with jQuery, it is even more likely.

Every help you can provide is highly appreciated :)

[UPDATE]

I got it working now. The problem was that I didn't check for the relatedTarget to be "outer" itself. So when the mouse leaves the content div and enters the outer div, mouseout fires and of course, outer is no child of itself. So I amended it to

$('#outer').on('mouseout', function(event) {
    if (!(event.relatedTarget.id == "outer") &&    
        !$(event.relatedTarget).isChildOf("outer")) {
        mouseIsOverMenu = false;
        menu_rollin();
    }
});

and that fixed the problem.

Answer:1

if i understood your question right.

This might help

$('#inner').on('mouseover', function() {
        mouseIsOverMenu = true;
        setTimeout(menu_rollout, 500);
    });

    $('#inner').on('mouseout', function(event) {
        if (!$(event.relatedTarget).isChildOf("outer")) {
            mouseIsOverMenu = false;
            menu_rollin();
        }
    });

What i did is i have changed the id of #outer to #inner.

Answer:2

I need to call a js function everytime a key is pressed in a textbox: <html> <script> function checkValidity() { alert("Checking..."); } </script>...

I need to call a js function everytime a key is pressed in a textbox: <html> <script> function checkValidity() { alert("Checking..."); } </script>...

How to display the JSON response in jsp page through ajax... function doAjaxPost() { var name = $('#name').val(); var password = $('#password').val(); var gender = $('#gender')....

How to display the JSON response in jsp page through ajax... function doAjaxPost() { var name = $('#name').val(); var password = $('#password').val(); var gender = $('#gender')....

  1. display json response in html
  2. display json response in html table
  3. display json response in angular
  4. display json response in angular 6
  5. display json response in chrome
  6. display json response in browser
  7. display json response in angularjs
  8. display json response in ajax
  9. display json response javascript
  10. display json response in php
  11. display json response in jsp
  12. display json response in datatable
  13. display json response in angular 2
  14. display json response in jquery
  15. display json response in div
  16. display json response in html angular
  17. display ajax json response in html
  18. laravel display json response
  19. curl display json response
  20. react display json response

Description: Using Javascript, I populate a YouTube link with video IDs that the user has selected, and end up with a URL like the following: https://www.youtube.com/watch_videos?video_ids=...

Description: Using Javascript, I populate a YouTube link with video IDs that the user has selected, and end up with a URL like the following: https://www.youtube.com/watch_videos?video_ids=...

  1. youtube create playlist missing
  2. youtube create playlist not working
  3. youtube create playlist from channel
  4. youtube create playlist without account
  5. youtube create playlist api
  6. youtube create playlist private
  7. youtube create playlist from liked videos
  8. youtube create playlist from queue
  9. youtube create playlist without channel
  10. youtube create playlist from links
  11. youtube create playlist 2020
  12. youtube create playlist 2019
  13. youtube create playlist mobile
  14. youtube create playlist invalid request
  15. youtube create playlist from search results
  16. youtube create playlist
  17. youtube create playlist from list of urls
  18. youtube create playlist error
  19. youtube create playlist from file
  20. youtube create playlist from search

I'm extending the DataTables defaults like so: $.extend(true, $.fn.dataTable.defaults, { lengthChange: false, deferRender: true, displayLength: 25, stateSave: false, serverSide: ...

I'm extending the DataTables defaults like so: $.extend(true, $.fn.dataTable.defaults, { lengthChange: false, deferRender: true, displayLength: 25, stateSave: false, serverSide: ...

  1. datatables refresh from ajax
  2. refresh datatable with new data
  3. refresh datatable with new json data
  4. refresh datatable with new data jquery
  5. refresh datatable with json data
  6. refresh datatable with jquery
  7. refresh datatable with new data c#
  8. refresh datatable with new data angular
  9. refresh datatable with angularjs
  10. primefaces refresh datatable from bean
  11. primefaces refresh datatable from backing bean
  12. jsf refresh datatable from bean
  13. refresh datatable from backing bean