Is this a valid test to check if a URL refers to an Image in JS/jQuery
<pre><code>$(function() {
    $("&lt;img&gt;", {
        src: "http://goo.gl/GWtGo",
        error: function() { alert("error!"); },
        load: function() { alert("ok"); }
    });
});
</code></pre>

<p>Got inspiration from <a href="http://stackoverflow.com/questions/3744266/how-can-i-test-if-a-url-is-a-valid-image-in-javascript">How can I test if a URL is a valid image (in javascript)?</a></p>

<p><strong>UPDATE</strong></p>

<p>The next step will be: how can I encapsulate this logic into a function. I tried this -> <a href="http://jsfiddle.net/wp7Ed/2/" rel="nofollow">http://jsfiddle.net/wp7Ed/2/</a></p>

<pre><code>$(function() {
    function IsValidImageUrl(url) {
        $("&lt;img&gt;", {
            src: url,
            error: function() { return false; },
            load: function() { return true; }
        });
    }
    alert(IsValidImageUrl("http://goo.gl/GWtGo"));
    alert(IsValidImageUrl("http://error"));
});
</code></pre>

<p>but of course it fails... how can I return from an internl event handler? Or how can I implement this?</p>
