ajax - Apply jQuery functions to appended Infinite Scroll elements -


i'm having incredibly hard time finding answer this. there must answer buried somewhere, haven't found yet.

in short, have elements being appended wordpress loop using infinite scroll. i'm not using isotope or masonry plugins loop, i'm being buried in wrong answers.

outside of header script call infinite scroll, have slew of other functions being loaded (window).load(function(){... , understand, appended elements should fall scope.

unfortunately they're not.

my question is, shouldn't (window).load execute on every applicable element after new ajax elements have been appended?

code available on request, i'm hoping simple syntax answer...

the answer question is: no, $(window).load() doesn't fire when elements appended, when window object's onload event fires, i.e., @ completion of initial page load.

the suggestion of event delegation founded, , of passing callback when instantiating infinite scroller, more so. assuming you're using this jquery infinite scroll plugin, might like:

$(window).load(function() {     // [...]     $('#infinite-scroll-element')         .infinitescroll({ /* options */ },                         // callback handle binding events on newly added elements                         function(newelements) {                             // iterate across elements added                             (var = 0; < newelements.length; i++) {                                 var thiselement = newelements[i];                                 // bind event handlers here, e.g.:                                 $(thiselement).click(function(evt) { /* ... */ });                                 $(thiselement).mouseover(function(evt) { /* ... */ });                             };                         });     // [...] }; 

other plugins presumably offer similar functionality.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -