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 answersall 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
Post a Comment