javascript - With jQuery, how can I use the "live" method to alert when a new element is added? -
first off, don't want plugin this... jquery has functionality 99% of want live() method.
basically, want change this:
$(".some-button").live("click", function() { alert('yay!'); }); into this:
$(".some-button").live(function() { alert('yay!'); }); so, i'm saying want fire method right away when element added page... jquery can sooo close because that's how adds "click" in example above!
how can achieve without adding plugin, rather, using same functionality "live" , "die" methods do?
there isn't cross-browser way this, , there's nothing in jquery allows it.
you'd have use plugin, or manage invoking code new elements manually.
the live()[docs] method , delegate()[docs] method event handling. code give them respond browser events, not dom manipulation.
the reason .live() won't because not run code when adding new elements dom. isn't monitoring dom changes. rather responding events bubble document, , invoking handler if matches selector gave it.
Comments
Post a Comment