Javascript jQuery How to load default image if
<p>I wanted to load the default image if the user's one didn't exist. I tried this but it didn't work.</p>

<pre><code>$('#avatar').load(function(){
    // ... loaded  
}).error(function(){
    // ... not loaded
    $(this).attr('src','/images2/no-avatar2.png');
});
</code></pre>

<p>Anyone know how I could do this?</p>

<p>Someone uses this:</p>

<pre><code>function loadDefault(f, ff) {
img = document.getElementById(f);
if(!img.complete) {
    img.src = ff;
}
if(typeof(img.naturalWidth) != "undefined" &amp;&amp; img.naturalWidth == 0) {
    img.src = ff;
}
}

function init() {
setTimeout("loadDefault('side_avatar', '/images/default/avatar_player_profile.gif')", 100);
setTimeout("imageResize(740)", 100);
tooltip = new ToolTip();
tooltip.init('hoverBox', 'loading...');

}
</code></pre>

<p>How could I use something like this?</p>
