The function myfunction() assigns elements on the fields to be displayed after the load(). But this is not what is happening. Only works properly if you use setTimeout(function());
How to run the code sync mode?
jQuery(document).ready(function() {
jQuery('#mydiv').load('page.html');
myfunction();
});
asked Jun 21, 2016 at 20:25
Alisson Linneker
2921 gold badge2 silver badges13 bronze badges
1 Answer 1
When your myFunction() runs the load is not yet done. jQuery.load() accepts a callback function that will run when the load is complete.
jQuery(document).ready(function() {
jQuery('#mydiv').load('page.html', function() {
myfunction();
});
});
answered Jun 21, 2016 at 20:28
Slippery Pete
3,1101 gold badge16 silver badges17 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
jeffjenx
Noticed we provided the same answer. I think you can just add the function name instead of calling it within another anonymous function, i.e.
.load('page.html', myfunction)lang-js