I'm using the following jquery code to show a contextual delete button only for table rows we are hovering with our mouse. This works but not for rows that have been added with js/ajax on the fly...
Is there a way to make this work with live events?
$("table tr").hover(
function () {},
function () {}
);
WARNING: There is a significant performance penalty with the live version of hover. It's especially noticeable in a large page on IE8.
I am working on a project where we load multi-level menus with AJAX (we have our reasons :). Anyway, I used the live method for the hover which worked great on Chrome (IE9 did OK, but not great). However, in IE8 It not only slowed down the menus (you had to hover for a couple seconds before it would drop), but everything on the page was painfully slow, including scrolling and even checking simple checkboxes.
Binding the events directly after they loaded resulted in adequate performance.
As of jQuery 1.4.1, the hover event works with
live()
. It basically just binds to the mouseenter and mouseleave events, which you can do with versions prior to 1.4.1 just as well:This requires two binds but works just as well.
jQuery 1.4.1 now supports "hover" for live() events, but only with one event handler function:
Alternatively, you can provide two functions, one for mouseenter and one for mouseleave:
.live()
has been deprecated as of jQuery 1.7Use
.on()
instead and specify a descendant selectorhttp://api.jquery.com/on/
http://api.jquery.com/live/
This code works: