When I dynamically add a new element, I want to apply some function to it. For example, to turn regular <input>
into date-time selector (via some plugin) I need to
$('.dt').dateTime();
The function above only works the first time I add elements during initialization.
Whenever I add them later using .append()
the function is not applied. For event listeners I use $(document).on()
instead:
$(document).on('click', '.dt', function () {});
and it works in any case.
What is the equivalent to use on creation?
On SO I've seen solutions to similar problems that either use function .live()
which is now deprecated, or use some sort of plugin which I don't want.
Is there any solution in plain jquery?