jquery - How to bind .hover() to dynamically created "li" elemtent? -



jquery - How to bind .hover() to dynamically created "li" elemtent? -

this question has reply here:

jquery .on function future elements, .live deprecated [duplicate] 2 answers

all solutions able find suggests utilize .live() method. of today deprecated.

.hover() works on "li" elements not created dynamically. 1 time append new "li" .hover() not triggered @ all.

anybody has figured 1 out?

the "hover" event has been deprecated delegated event handling such .on() per .on() jquery doc pages.

instead, need utilize .on() delegated event handling mouseenter , mouseleave , event handler each.

for example:

$(document).on("mouseenter", "li", function() { // hover starts code here }); $(document).on("mouseleave", "li", function() { // hover ends code here });

in real code, select static parent object much closer dynamic li tags document object improve performance.

jquery

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -