Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery :: live hover problem

An example jsfiddle is here. Try to hover the red square and then hover the blue one. Why is it flickering? How can I prevent the blue square to disappear?

(This is actually a tab and it's ex icon, that appear only when hovered)

JavaScript:

$("#foo").live("mouseover mouseout", function(e) {
    if (e.type == "mouseover") {
       $("#foo").append("<div id='bar'>");
    } else {
        $("#bar").remove();
    }
});

CSS:

#foo {
 width: 100px;
 height: 50px;
 background: red;   
}

#bar {
    width: 10px;
    height: 10px;
    background: blue;
}

Thanks

like image 409
CamelCamelCamel Avatar asked Jan 27 '26 05:01

CamelCamelCamel


2 Answers

Not sure what you intent todo, but is it what you're looking for: http://jsfiddle.net/PXExS/4/

$("#foo").live("mouseenter mouseleave", function(e) {
    if (e.type == "mouseenter") {
       $("#foo").append("<div id='bar'>");
    } else {
        $("#bar").remove();
    }
});
like image 56
Mrchief Avatar answered Jan 28 '26 19:01

Mrchief


You can achieve the same thing by doing

$("#foo").live("hover", function(e) {
    $("#bar").toggle();
});

Check working example at http://jsfiddle.net/PXExS/9/

like image 21
Hussein Avatar answered Jan 28 '26 20:01

Hussein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!