This bugs me. I just watched Philip Roberts's video about the event loop and got an understanding of how the API calls will eventually put callbacks in the callback queue. But he only mentioned the XMLHtppRequest and the time out functions. What about DOM API (document.getElementById, document.appendChild)? Does they make the same effect?
This bugs me. I just watched Philip Roberts's video about the event loop and got an understanding of how the API calls will eventually put callbacks in the callback queue. But he only mentioned the XMLHtppRequest and the time out functions. What about DOM API (document.getElementById, document.appendChild)? Does they make the same effect?
Share Improve this question asked May 6, 2018 at 13:40 Best_NameBest_Name 1593 silver badges13 bronze badges 1- Is DOM manipulation asynchronous (when using the API provided by the browsers like getElementById or appendChild)? I don't think so – Muhammad Usman Commented May 6, 2018 at 13:43
2 Answers
Reset to default 7DOM manipulation is synchronous, however, the browser's re-rendering of the page in response to a DOM update is asynchronous. This can give the illusion of an asynchronous DOM update.
No, they don't do any long-running stuff in the background that would require notifying you when it is ready. They directly manipulate the DOM tree. You can also infer this from the fact that there are no callbacks involved.