After function completes, redirect to URL
<p>I have a bit of HTML which is unfortanetly an inherited onclick:</p>

<pre><code>&lt;a href="http:www.intendedlink.com" onclick="tracker(this, 'HondaAccord');return false;"&gt;Buy a Car&lt;/a&gt;
</code></pre>

<p>What I would like is for the image to be generated onclick, appened to the div <code>car</code> and then transfered to the URL. As so:</p>

<pre><code>function tracker(theLink, trackID) {
    var trackUrl = "http://www.mysite.com?something=" + trackID + "&amp;val1&amp;val2;";
    var img = $('&lt;img&gt;');
    img.attr('src', trackUrl);
    img.appendTo('div.car');
    $(function () {=
        $(this).on('click', function () {
            var url = theLink;
            if (url) {
                window.location = theLink;
            }
        });
    });
}
</code></pre>

<p>The image is generated but I'm never sent to the new link. Perhaps I don't even need to bind? But I want to be sure I'm not sent until the image is appended to <code>car</code> otherwise the tracking response is cut off prematurely.</p>
