You put your JS code in a separate file (you load it into the downloaded html file) and use getScript as follows:
$('#foo').load('bar.html', function(){ $.getScript("js/fileName.js");
So, create a separate JS file (it is recommended not to mix it with an html or html document) and call it inside your bar.html file:
<script href="js/fileName.js"></script>
With this, you can also get this file to work with downloads using getScript .
source share