2

I am facing one small Issue in displaying/hiding any div on hovering any anchor tag.

Currently I tried with Mouseenter and MouseLeave functions but Its not smooth.

Clickable Link:<a class="clickmeToSeeDiv" href="##"></a>

JS code:

    $('.clickmeToSeeDiv').live("mouseenter",function(){
        $('.leftborderActive').show();
    });
    $('.clickmeToSeeDiv').live("mouseleave",function(){
        $('.leftborderActive').hide();          

    });

Above code sometime works sometimes not. Please suggest if you all have any Idea or a better solution.

Thanks Sham

Sks
  • 612
  • 7
  • 23
  • You have answer here [http://stackoverflow.com/questions/5210033/show-div-on-hover-with-only-css][1] with only css. [1]: http://stackoverflow.com/questions/5210033/show-div-on-hover-with-only-css – Zivko Mar 25 '14 at 17:39
  • I would suggest not using `live`, but `on`. – Karl-André Gagnon Mar 25 '14 at 17:40

3 Answers3

3

live event is deprecated, use .on() instead (Attach an event handler function for one or more events to the selected elements).

Try this:

$(document).ready(function(){
    $(".leftborderActive").hide(); // hide div on DOM ready
    $( ".clickmeToSeeDiv" ).mouseenter(function() { // anchor mouseover event
        $(".leftborderActive").show(); // show div
    }).mouseleave(function() { //anchor mouseleave event
        $(".leftborderActive").hide(); //hide div
    });
});

DEMO

or

$(document).ready(function(){
     $(".leftborderActive").hide();
    $(document).on('mouseenter mouseleave','.clickmeToSeeDiv',function(){
        $('.leftborderActive').toggle();
    });
});
Kiran
  • 20,167
  • 11
  • 67
  • 99
2

the method 'live' is deprecated, use 'on' instead.

$(document).on('mouseenter mouseleave', '.clickToSeeDiv', OnDivClick);

function OnDivClick(){
    $('.clickToSeeDiv').toggle();
}
Sérgio S. Filho
  • 364
  • 1
  • 4
  • 13
0

You could try JQuery's animate functions or set a timer on the show and hide methods so that they make the div operate a little more smoothely.

Also, make sure to cancel any previous events when you call the enter or leave methods so that the animations don't stack.

user3446496
  • 361
  • 1
  • 8