Creating "onload" functionality in Dynamic HTML

491 Views Asked by At

Using jquery ajax I populate contents of a div with HTML.

This new HTML data has javascript code (this part works correctly). However this javascript also has

$(document).load(function() { ... });

This part does not work since document is already loaded!

How should I handle this?

2

There are 2 best solutions below

0
On BEST ANSWER

Nothing fancy is actually needed. It seems that dynamically loaded javascript is executed after the dynamic content is parsed by the browser.

3
On

Are you sure it's always going to be loaded via AJAX? If so, why not just remove the $(document).load() altogether?