Search code examples
javascriptjquerymouseeventmouseoverjquery-events

How to catch mouseover event when dynamically added where mouse is already over the element?


I dynamically add this

$(ele).on("mouseover")

when user has mouse over the element, but it seems that mouseover event triggers only when I reenter element.

Here is example in jsFiddle (Click on <div> to add event listener)

How can I achieve this without manually triggering .mouseover() ?


Solution

  • Best solution I came up with was (Thanks to Brandon's suggestion):

    Store x,y pos in document (drops performance on webpage a bit):

    $(document).mousemove(function (e) {
        // Set global values
        window.mouseXPos = e.pageX;
        window.mouseYPos = e.pageY;
    });
    

    And then when animation is finished:

    $(document.elementFromPoint(window.mouseXPos, window.mouseYPos)).trigger("mouseenter");