javascript - How to raise a jquery event when an element with some class is created dynamically -


is possible raise jquery event when element class created dynamically? mean. have following;

... <div id="lotocontent"></div> ... 

using jquery ajax, i'm retrieving several rows server , appending them "lotocontent" div. each row has empty span element looks this

<span class="lotodatetime" data-date="123456"></span> 

the value of data-date attribute unix time-stamp retrived database. once rows added, following javascript function called;

function processdatetimes() {    //process dates     $('.lotodatetime').each(function () {         var timestamp = $(this).data('date');         $(this).text(getdatetimefromserverunixtimestamp(timestamp));     });  }  function getdatetimefromserverunixtimestamp(timestamp) {   //this function takes unix time-stamp , converts date , time    // 08/09/2013 12:09 based on browser time } 

this works fine, wondering if there way automatically call processdatetimes() when date spans created instead of manually calling function after created. have in mind;

$('#lotocontent').on('someevent', '.lotodatetime', function() {   processdatetimes(); }); 

thanks.

the word may looking observables. in essence, when dom (or in situation span element) updated you'd trigger event.

for answer i'd direct attention response,

https://stackoverflow.com/a/240663/191006

ken illustrates capturing dom changes @ top allow pick , choose on inner elements.

$('body').change(function(event){      if( $(event.target).hasclass("lotodatetime") )         processdatetimes();   }); 

you clean up... don't need check class am... hope helps going in right direction.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -