Possible Duplicate:
jQuery 1.7 - Turning live() into on()
.live() vs .on() method
I have the following code (which I've simplified for this) which worked fine alongside jquery-1.7.
$("td.ui-datepicker-week-col a").live("click", function () {
alert("hello");
});
I'm trying to upgrade my code though so I can upgrade my jQuery pack version so I've changed it to this.
$("td.ui-datepicker-week-col").on("click", "a", function () {
alert("hello");
});
This doesn't do anything though. It doesn't throw any errors either so I can't see where the problem is.
Any ideas?
If you don't have "td.ui-datepicker-week-col"
element at start, then you must choose an existing permanent set. For example
$(document).on("click", "td.ui-datepicker-week-col a", function () {
alert("hello");
});
The on
function, contrary to live
, will only work with the set as it is defined when you call the binding function. What is dynamic is the interpretation of the selector passed as argument to on
when an event occurs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With