Does jQuery.on() work for elements that are added after the event handler is created?
Posted
by
orokusaki
on Stack Overflow
See other posts from Stack Overflow
or by orokusaki
Published on 2012-03-21T23:24:42Z
Indexed on
2012/03/21
23:29 UTC
Read the original article
Hit count: 156
jquery-events
|jquery-live
I was under the impression all this time that .on()
worked like .live()
with regards to dynamically created elements (e.g. I use $('.foo').on('click', function(){alert('click')});
and then an element with the class foo
is created due to some AJAX, now I'm expecting a click on that element to cause an alert). In practice, these weren't the results I got. I could be making a mistake, but could somebody help me understand the new way to achieve these results, in the wake of .on()
?
Thanks in advance.
© Stack Overflow or respective owner