1

I have the below piece of code:

$("some_html_stuff").insertAfter('.some_element');

I then have other JS code which I need to be sure will execute AFTER the insertAfter function has finished its business. How can a achieve this? I looked at closures and a bunch of other stuff, but I don't seem to be able to figure this out.

asked Mar 7, 2012 at 18:44
2
  • 1
    If you're having an issue in your code, perhaps you should explain it. You seem to have assumed the cause of an issue, and are therefore asking about the assumed cause instead. What is the XY problem? Commented Mar 7, 2012 at 18:56
  • Yes, you're right. I did indeed assume that my code wasn't working as expected because I automatically assumed that insertAfter is async. It's all cleared up now, code is working nicely. Thanks for your help. Commented Mar 7, 2012 at 19:07

2 Answers 2

2

This is a synchronous command. Nothing further will execute until it's finished.

$("some_html_stuff").insertAfter('.some_element');
// Do something after
answered Mar 7, 2012 at 18:47
Sign up to request clarification or add additional context in comments.

Comments

1

.insertAfter is not asynchronous, so just add your other code right after that line of code.

answered Mar 7, 2012 at 18:46

Comments

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.