Show a javascript loader image while function is executing
<p>I want to click a button, show a loader image, execute a time-consuming function, hide the loader image.  When I attempt this, the page freezes until the entire event runs, so the loader image is never seen.</p>

<p>Here is a sample:</p>

<pre><code>$('#btn').click(function() {
    $('#LoadingImage').show();
    &lt;time consuming function&gt;
    $('#LoadingImage').hide();
});
</code></pre>

<p>How can I distinctly show the loader image, update the screen, run the function, hide the loader image?</p>
