What is the best way to reapply JS to dynamic generated content? I said "reapply JS" and not "rebind events" because a meant "reapply JS that bind events and also changes the dom", what I have done so far is something like this:
main.js:
function repplyDynamic(){
$('.dynamic:not(.js-initialized)').each(function(){
$(this).addClass('js-initialized').append('<div class="chaging_dom"></div>').click(function(){
alert("Ae!");
});
});
}
other_code.js
$('body').append('<div id="dynamic">content</div>'); // could be a ajax call
reapplyDynamic();
But I think this is very messy. Do you guys have a better approach?