Is it possible to raise a jquery event when an element with a certain class is created dynamically? This is what I mean. I have the following;
...
<div id="lotoContent"></div>
...
Using jquery ajax, I'm retrieving several rows from the server and appending them to the "lotoContent" div. Each row has an empty span element that looks like this
<span class="lotoDateTime" data-date="123456"></span>
The value of the data-date attribute is a unix time-stamp retrived from the database. Once the rows are added, the following javascript function is called;
function processDateTimes() {
//process dates
$('.lotoDateTime').each(function () {
var timeStamp = $(this).data('date');
$(this).text(getDateTimeFromServerUnixTimeStamp(timeStamp));
});
}
function getDateTimeFromServerUnixTimeStamp(timeStamp) {
//this function takes the unix time-stamp and converts it to Date and Time
// like 08/09/2013 12:09 based on the browser time
}
This works fine, but I was wondering if there is a way to automatically call processDateTimes() when the date spans are created instead of manually calling the function after they are created. Something like this is what I have in mind;
$('#lotoContent').on('SomeEvent', '.lotoDateTime', function() {
processDateTimes();
});
Thanks.