I know that live() can be used to support event handlers for current AND “added later” DOM elements.
I wonder how to do the same thing with each()?
Like if I have $('.something_or_other').each() but then another DOM element with class="something_or_other" gets added? How can I set it up to automatically apply the each iteration to this new DOM element?
OR, what can I call after adding the new DOM element to reapply the each() rules.
(Showing my age a bit here but in Behaviour we can use Behaviour.apply() to reapply ALL of the rules!)
As @meder noted, you should really just do this manually. You can use the same function for both if you like.
If you really don’t want to do that, there’s a plugin called
livequerythat will run code when an element that matches a selector is added to (or removed from) the DOM.It costs a bit of extra overhead, but it is an option.
http://brandonaaron.net/code/livequery/docs