Posted by Michael Alfaro on June 28, 2012

How to setup a Jquery Live Hover event properly

Had to find a solution for this today as we have a tooltip object that works through Javascript on hover.  Our problem was that we had a section of the page that was dynamically created if certain choices were made and it had a tooltip in that section.  Since we didn’t have .live in the JS, the hover event wouldn’t work.  I found the solution here in the comments of the posted solution: http://stackoverflow.com/questions/2262480/jquery-live-hover

According to the solution, it was supposed to be this:

$('div.help').live("hover", function () {
//code here
});

But that doesn’t work, you need to do this:

$('div.help').live("mouseenter mouseleave", function () {
//code here
});

Topics: , ,

Add a Comment



 

Showing 2 Comments

  1. Krunal

    $(‘div.help’).live(‘mouseover mouseout’,function(event){
    if (event.type == ‘mouseover’) {
    //your code here
    }
    else
    {
    //your code here
    }
    });

  2. Krunal Bhingradiya

    try it…. this is successfully run…

    $(‘div.help’).live(‘mouseover mouseout’,function(event){
    if (event.type == ‘mouseover’) {
    //your code here
    }
    else
    {
    //your code here
    }
    });