问题 Based on my own experience, and consistent with this answer, changes to the UI aren't made while JavaScript code is running. Example When I click a button "Run Script", I want a loading animation to appear, then I want some JavaScript to run, and when the JavaScript is finished running, I want the loading animation to disappear. I've created a codepen here, which (predictably) fails. The most relevant portion of code is: $('#run-script-btn').on('click', function() { startLoading();