jquery execution order
<p>Consider the following code:</p>

<pre><code>function searchText() {
    if($('#searchtext').val() == null || $('#searchtext').val().trim() == '') {
         alert('must provide a text to search for');
     return false;
    }

    urllink='http://search.twitter.com/search.json?q=' + escape($('#searchtext').val().trim()) + '&amp;callback=?';
    $('#results').html(urllink);

    $.getJSON(urllink,function(data) {
         var resultT = {};
         $('#results').html(data.results[0].profile_image_url);

         return data.results;
    });
}

$('#gosearch').click(function() {
    var data = searchText();
    if(data == null)
         alert('null');

    return false;
});
</code></pre>

<p>I have a breakpoint in firebug in <code>return data.results</code> of <code>searchText()</code>. But it seems that <code>searchText</code> is executed but I do not stop in my break point. It rather checks for data, which is <code>null</code>, and executes <code>alert('null')</code>. then it stops in my break point inside <code>searchText</code>. </p>

<p>Why is this happening? Can't I execute functions inside events and wait them to finish before moving to next line in code?</p>

<p>thanks</p>
