want to hide image when image is not found at the src location?

jQuery('img').bind('error',function(){
            alert('hi');
        jQuery(this).hide(); 
        });

I have written this code but non available images are not hiding and still showing cross sign. Can anybody point out what can be wrong. I am writing this under document.ready and i have tried it under window.onload as well.

Answers


The problem seems to be that by the time you bind your error event, the image's onerror has already fired. You can fire it again by resetting the img.src after binding the event. The following worked on IE8, FF, and Chrome.

$('img').error(function(){
    alert('hi');
    $(this).hide(); 
});

$('img').each(function() { this.src = this.src; });

jsFiddle is here: http://jsfiddle.net/7cnQN/


Need Your Help

Performance improvement for GZ to ORC File

hive hdinsight

Please let me know Is there any faster way to move (*.gz) to ORC table directly.

Concurrent code analyzer

java concurrency synchronized petri-net

I was wondering if there is any framework or application(app)/program out there that can analyze the concurrency of any java code?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.