-->

jQuery `[jQuery created Element].is(“:hover”)` Onl

2019-07-13 06:25发布

问题:

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