Block of UI until another JavaScript code fragment finishes using jQuery 
<p>I am not using Ajax, but I wanted to display a loading screen until another JavaScript code fragment finishes.
I tried below, but it does not seem to be working.</p>

<p>Any help highly appreciated.</p>

<pre><code>&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Load Test&lt;/title&gt;
        &lt;script type="text/javascript" src="jquery-1.6.1.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript" src="jquery.blockUI.js"&gt;&lt;/script&gt;

        &lt;script type="text/javascript"&gt;
            function linkHandler(){
                for(i=0;i&lt;2;i++){
                    for(j=0;j&lt;500;j++){
                        document.getElementById("datafield").value=document.getElementById("datafield").value+new Date()+"\n";
                    }
                }
            }
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;textarea name="datafield" id="datafield" cols="80" rows="15"&gt;&lt;/textarea&gt;
        &lt;br/&gt;
        &lt;a href="javascript:void(0)" &gt;Link 1&lt;/a&gt;&lt;br/&gt;
        &lt;a href="javascript:void(0)" &gt;Link 2&lt;/a&gt;&lt;br/&gt;
        &lt;a href="javascript:void(0)" &gt;Link 3&lt;/a&gt;&lt;br/&gt;
        &lt;a href="javascript:void(0)" &gt;Link 4&lt;/a&gt;&lt;br/&gt;
        &lt;a href="javascript:void(0)" &gt;Link 5&lt;/a&gt;&lt;br/&gt;

        &lt;script type="text/javascript"&gt;
            $('a').click(function(event) {
                $.blockUI();
                document.getElementById("datafield").value=document.getElementById("datafield").value+new Date()+" Screen blocked \n";
                linkHandler();
                document.getElementById("datafield").value=document.getElementById("datafield").value+new Date()+" Function over\n";
                   $.unblockUI();
                   document.getElementById("datafield").value=document.getElementById("datafield").value+new Date()+" Screen unblocked \n";
                   return false;
            });
        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
