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
Boyan Georgiev
1,5813 gold badges13 silver badges16 bronze badges
-
1If 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?user1106925– user11069252012年03月07日 18:56:05 +00:00Commented 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.Boyan Georgiev– Boyan Georgiev2012年03月07日 19:07:55 +00:00Commented Mar 7, 2012 at 19:07
2 Answers 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
Ben Lee
53.5k15 gold badges129 silver badges146 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
.insertAfter is not asynchronous, so just add your other code right after that line of code.
answered Mar 7, 2012 at 18:46
bfavaretto
71.9k18 gold badges118 silver badges162 bronze badges
Comments
lang-js