For Jquery replaceWith(newCode) method:
The new code contains a number of scripts to executed when document is ready. For example
<div>
<script>$(function(){ foo1(); });</script>
<script>$(function(){ foo2(); });</script>
<script>$(function(){ foo3(); });</script>
</div>
After replaceWith(...) is called, function foo4(..) needs to execute after foo1(), foo2(), and foo3() are executed.
I tried this:
$(".foo").replaceWith(newCode);
$(function(){ foo4(); }
But foo4() is called before foo1, foo2, and foo3.
How to execute a function after all functions (document ready) in the replacement code are executed?