I have parts of pages that are replaced with HTML received through AJAX calls. Some of the returned HTML files have JavaScript that needs to be run once to initialize the accompanying HTML (setting up event handlers).
Since the document is already loaded, when I replace HTML chunks with the jQuery .html function, << 21> is not executed because the page loaded long before, and this is just a fragment of the HTML being replaced.
What is the best way to attach event handlers whose code is packed with HTML of interest when this content is loaded via AJAX? Should I just put the javascript procedural block after the HTML, so when I insert a new HTML block, jQuery will execute javascript immediately? Is HTML specifically in the DOM and ready for JavaScript action that is in the same .html call?
source share