From jQuery 1.7 + .live () is deprecated , and .delegate () has been replaced by the .on () method.
Use .on () and .off () instead of .live () and. Die (). Use .on () instead of .delegate ().
Converting old code is simple as described here .
You need to call events that .hover() displayed separately, for example:
$("li.favorite_item").live('mouseenter', function() { $(this).append($(" <a href='#' class='button'>x</a>")); }).live('mouseleave', function () { $(this).find("a:last").remove(); });
.hover() not an event function, for example .click() , it is just a special shortcut for .mouseenter(handler1).mouseleave(handler2) ... so you need to do the same in the .live() call.
If you are using jQuery 1.4.3+, you can use a map to simplify it, for example:
$("li.favorite_item").live({ mouseenter: function() { $(this).append($(" <a href='#' class='button'>x</a>")); }, mouseleave: function () { $(this).find("a:last").remove(); } });
Also, if indicated on a specific <ul> , .delegate() is a better option, for example:
$("#myUL").delegate("li.favorite_item", { mouseenter: function() { $(this).append($(" <a href='#' class='button'>x</a>")); }, mouseleave: function () { $(this).find("a:last").remove(); } });
Nick craver
source share