.on("hover", ...) chaining not working

Rob M

I have a js file that has .on("click" , ..) chaining happening that I would like to also add a hover event to. My code is:

}).on('hover' , '.tooltip' , function (e) {
   if (e.type == "mouseenter") {
      var tip = $(this).attr('title');
      var tipTemp = $(this).attr('data-title', tip);
      $('#tooltip').remove();
      $(this).parent().append('<div id="tooltip">' + tipTemp + '</div>');
      $(this).removeAttr('title');      
      $('#tooltip').fadeIn(300);
    }else{
      $(this).attr('title', $(this).attr('data-title'));
      $('#tooltip').fadeOut(300);
      $(this).removeAttr('data-title');
    }
});

I understand that I can really only pass one function this way so I am checking for the event type to trigger the appropriate behavior. This doesn't seem to be working for me. Any ideas?

OutFall

I think this is what you want

}).on('mouseenter' , '.tooltip' , function (e) {
    var tip = $(this).attr('title');
    var tipTemp = $(this).attr('data-title', tip);
    $('#tooltip').remove();
    $(this).parent().append('<div id="tooltip">' + tipTemp + '</div>');
    $(this).removeAttr('title');      
    $('#tooltip').fadeIn(300);
});

}).on('mouseleave' , '.tooltip' , function (e) {
    $(this).attr('title', $(this).attr('data-title'));
    $('#tooltip').fadeOut(300);
    $(this).removeAttr('data-title');
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related