0

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

1 Answer 1

4

When your myFunction() runs the load is not yet done. jQuery.load() accepts a callback function that will run when the load is complete.

http://api.jquery.com/load/

jQuery(document).ready(function() {
 jQuery('#mydiv').load('page.html', function() {
 myfunction();
 }); 
});
answered Jun 21, 2016 at 20:28
Sign up to request clarification or add additional context in comments.

1 Comment

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)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.