Document listener jQuery.each

94 views Asked by At

We have a web app that spits out elements server-side and some through Backbone -- and have a simple jQuery.each() statement that flips through elements on the page and adds/removes certain classes based on size of the component. I'm calling this within an "init" function, but it's obviously not working for any elements that are not on the page when loaded; within the Backbone scope.

I'd rather not re-call this function in each Backbone instance (in-case we end up adding more views that render other items needed by this function) and wanted something like a $(document).on() function to work like I do for normal clicks, hovers, etc. I haven't found any examples on how I could make this work with jQuery.each(), so would appreciate any insight on how I'd go about this.

1

There are 1 answers

0
Zach On

Mutation Observers are what I'll go with.