jQuery `[jQuery created Element].is(“:hover”)` Only Seems To Work In Chrome

随声附和 提交于 2019-12-14 02:01:51

问题


Please see the code below (very stripped back and not my full function). I've also got a fiddle that you can test it at: https://jsfiddle.net/glenn2223/uk7e7rwe/1/

var 
    hov = $("<div class=\"over\">I'm Over You</div>"),
    box = $("<div>Result: WAITING</div>")


$("body").append(hov).append(box);

$("#MeHover").on('mouseleave', function(){
    var d = new Date();
    box.text("Result: " + hov.is(":hover").toString().toUpperCase() );
});

We have a div and div.over overlaps it slightly. When you move from div to div.over I want the function to return true.

In my full function: this stops it from hiding the div.over element.

Opening it in Chrome it works as expected. However, it's not in pretty much everything else (Tested in: Edge, IE11 and Firefox).


回答1:


Okay so we've found out why it doesn't work the :hover was removed from .is() a while back.

Rather than changing this question to suit my findings I will ask another (saves confusion).


My New Question: Keep jQuery Appended Element Open When Hovering It



来源:https://stackoverflow.com/questions/46320025/jquery-jquery-created-element-ishover-only-seems-to-work-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!