<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Using jQuery to Load Alternate Images</title>
	<atom:link href="http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/</link>
	<description>My thoughts on ColdFusion, Flex and other RIA stuff....</description>
	<lastBuildDate>Tue, 07 Feb 2012 10:21:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Ashish Chotalia</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-6525</link>
		<dc:creator>Ashish Chotalia</dc:creator>
		<pubDate>Thu, 03 Feb 2011 13:11:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-6525</guid>
		<description>You can do like this as well:




$(document).ready(function(){ 
    $(&quot;img&quot;).each(function(index) {
        $(this).error(function() {
            $(this).unbind(&quot;error&quot;).attr(&quot;src&quot;, &quot;/images/NoImage.png&quot;); // If you want to replace with any blank image.

            $(this).hide();//You can simply Hide it using this.
        });
        $(this).attr(&quot;src&quot;, $(this).attr(&quot;src&quot;));
  });    
});

More info &lt;a href=&quot;http://tinyurl.com/5tvsdt9&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>You can do like this as well:</p>
<p>$(document).ready(function(){<br />
    $(&#8220;img&#8221;).each(function(index) {<br />
        $(this).error(function() {<br />
            $(this).unbind(&#8220;error&#8221;).attr(&#8220;src&#8221;, &#8220;/images/NoImage.png&#8221;); // If you want to replace with any blank image.</p>
<p>            $(this).hide();//You can simply Hide it using this.<br />
        });<br />
        $(this).attr(&#8220;src&#8221;, $(this).attr(&#8220;src&#8221;));<br />
  });<br />
});</p>
<p>More info <a href="http://tinyurl.com/5tvsdt9" rel="nofollow">here</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anuj Gakhar</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-5898</link>
		<dc:creator>Anuj Gakhar</dc:creator>
		<pubDate>Mon, 29 Nov 2010 17:53:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-5898</guid>
		<description>Thanks for the fix @bk, much appreciated.</description>
		<content:encoded><![CDATA[<p>Thanks for the fix @bk, much appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bk</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-5897</link>
		<dc:creator>bk</dc:creator>
		<pubDate>Mon, 29 Nov 2010 17:49:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-5897</guid>
		<description>Rob/Anuj/Dans - not 100% sure but I think the naturalWidth detection for Firefox is wrong as it causes all images in IE to be marked as broken because this.naturalWidth == &#039;undefined&#039; is always true in IE.  This seems to work in all browsers instead:

$.fn.broken = function(img){
  return this.each(function(){
	if(!this.complete &#124;&#124; (typeof this.naturalWidth != &#039;undefined&#039; &amp;&amp; this.naturalWidth == 0))
	  this.src = img;
	});
};

$(window).load(function () {
	$(&#039;#whatever&#039;).broken(&#039;/whatever.jpg&#039;);
});</description>
		<content:encoded><![CDATA[<p>Rob/Anuj/Dans &#8211; not 100% sure but I think the naturalWidth detection for Firefox is wrong as it causes all images in IE to be marked as broken because this.naturalWidth == &#8216;undefined&#8217; is always true in IE.  This seems to work in all browsers instead:</p>
<p>$.fn.broken = function(img){<br />
  return this.each(function(){<br />
	if(!this.complete || (typeof this.naturalWidth != &#8216;undefined&#8217; &amp;&amp; this.naturalWidth == 0))<br />
	  this.src = img;<br />
	});<br />
};</p>
<p>$(window).load(function () {<br />
	$(&#8216;#whatever&#8217;).broken(&#8216;/whatever.jpg&#8217;);<br />
});</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robson Pinto</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-4916</link>
		<dc:creator>Robson Pinto</dc:creator>
		<pubDate>Sun, 08 Aug 2010 01:27:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-4916</guid>
		<description>This solution is perfect! Join idea of Anuj and Dans:

$.fn.broken = function(img){
	return this.each(function(){
		if(!this.complete &#124;&#124; typeof this.naturalWidth == &#039;undefined&#039; &#124;&#124; this.naturalWidth == 0) this.src = img;
	});
};

$(&#039;img&#039;).broken(&#039;http://www.tranism.com/weblog/images/broken_ipod.gif&#039;);</description>
		<content:encoded><![CDATA[<p>This solution is perfect! Join idea of Anuj and Dans:</p>
<p>$.fn.broken = function(img){<br />
	return this.each(function(){<br />
		if(!this.complete || typeof this.naturalWidth == &#8216;undefined&#8217; || this.naturalWidth == 0) this.src = img;<br />
	});<br />
};</p>
<p>$(&#8216;img&#8217;).broken(&#8216;<a href="http://www.tranism.com/weblog/images/broken_ipod.gif" rel="nofollow">http://www.tranism.com/weblog/images/broken_ipod.gif</a>&#8216;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HTML onerror: The Good, the Bad, and the Ugly &#171; sociomantic labs</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-4814</link>
		<dc:creator>HTML onerror: The Good, the Bad, and the Ugly &#171; sociomantic labs</dc:creator>
		<pubDate>Tue, 27 Jul 2010 14:02:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-4814</guid>
		<description>[...] it&#8217;s not added to an element inline. I did a bit more research and &#8211; inspired by this article &#8211; opted to use Javascript to add the onerror event to the required elements once the DOM had [...]</description>
		<content:encoded><![CDATA[<p>[...] it&#8217;s not added to an element inline. I did a bit more research and &#8211; inspired by this article &#8211; opted to use Javascript to add the onerror event to the required elements once the DOM had [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-3657</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Sun, 18 Apr 2010 21:08:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-3657</guid>
		<description>Good point. I haven&#039;t tested it, but from memory I recall that it will display the red X in the top left corner, on top of the background image. The same goes for other browsers also.</description>
		<content:encoded><![CDATA[<p>Good point. I haven&#8217;t tested it, but from memory I recall that it will display the red X in the top left corner, on top of the background image. The same goes for other browsers also.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nagaraj Hubli</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-3653</link>
		<dc:creator>Nagaraj Hubli</dc:creator>
		<pubDate>Thu, 15 Apr 2010 07:17:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-3653</guid>
		<description>@Peter with the css fix, wouldn&#039;t the IE browser still show the &quot;red x&quot; for the broken images?</description>
		<content:encoded><![CDATA[<p>@Peter with the css fix, wouldn&#8217;t the IE browser still show the &#8220;red x&#8221; for the broken images?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-3519</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Tue, 12 Jan 2010 20:03:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-3519</guid>
		<description>@Denis:

It will actually load an extra image for EVERY image in the document, not only for the broken ones.

However, images are cached quite efficiently (with default settings), so the offline.jpg will only be downloaded once for your whole site, even if the user revisits a few days later.

I would guess the resource usage in the browser would also be minimal, since the browser knows it&#039;s the same image being reused everywhere.

I would definitely guess the resource usage is (far) less using one CSS command (which is handled internally by the browser) than looping through all the images in the document using JavaScript.</description>
		<content:encoded><![CDATA[<p>@Denis:</p>
<p>It will actually load an extra image for EVERY image in the document, not only for the broken ones.</p>
<p>However, images are cached quite efficiently (with default settings), so the offline.jpg will only be downloaded once for your whole site, even if the user revisits a few days later.</p>
<p>I would guess the resource usage in the browser would also be minimal, since the browser knows it&#8217;s the same image being reused everywhere.</p>
<p>I would definitely guess the resource usage is (far) less using one CSS command (which is handled internally by the browser) than looping through all the images in the document using JavaScript.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Denis</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-3518</link>
		<dc:creator>Denis</dc:creator>
		<pubDate>Tue, 12 Jan 2010 15:37:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-3518</guid>
		<description>@Peter: That would seem to work but would it not then load that extra image for every image broken or not? This might seem like a small issue as it&#039;s just one error image but if you have different error images and or a complex page redraw time etc would be effected heavily?</description>
		<content:encoded><![CDATA[<p>@Peter: That would seem to work but would it not then load that extra image for every image broken or not? This might seem like a small issue as it&#8217;s just one error image but if you have different error images and or a complex page redraw time etc would be effected heavily?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anuj Gakhar</title>
		<link>http://www.anujgakhar.com/2009/03/16/using-jquery-to-load-alternate-images/comment-page-1/#comment-3454</link>
		<dc:creator>Anuj Gakhar</dc:creator>
		<pubDate>Tue, 10 Nov 2009 11:24:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.anujgakhar.com/?p=347#comment-3454</guid>
		<description>Peter, that is a good trick specially if you dont use any transparent images. thanks for the tip.</description>
		<content:encoded><![CDATA[<p>Peter, that is a good trick specially if you dont use any transparent images. thanks for the tip.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

