Replace broken Image using JQuery

Replace broken Image using JQuery

Sir

My web page contains a lot of images. But when it will not loaded properly, it shows a broken image.

How can I fix it so that broken image will be replaced by error image automatically. Please Mention code.

Best regards

View Answers

December 11, 2010 at 5:34 PM

Dear friend

Use the following code :

$(window).bind('load', function() { $('img').each(function() { if((typeof this.naturalWidth != "undefined" && this.naturalWidth == 0 ) || this.readyState == 'uninitialized' ) { $(this).attr('src', 'missing.jpg'); } }); })

This code will replace the broken image with default image set by you.


January 25, 2011 at 12:05 PM

$(document).ready(function(){ 
    $("img").each(function(index) {
        $(this).error(function() {
            $(this).unbind("error").attr("src", "/images/NoImage.png");
            // If you want to replace with any blank image.

$(this).hide();//You can simply Hide it using this.
    });
    $(this).attr("src", $(this).attr("src"));

 });
});









Related Tutorials/Questions & Answers:
Replace broken Image using JQuery
Replace broken Image using JQuery  Sir My web page contains a lot of images. But when it will not loaded properly, it shows a broken image. How can... will replace the broken image with default image set by you
Crop image Using JQuery, servlet or JSP.
Crop image Using JQuery, servlet or JSP.  Hi sir I need the code of Cropping image using JQuery with the help of servlet or JSP. I need both the code Client side as well as of server side. Please Help me
Advertisements
Zoom Image section using jQuery plug-in
Zoom Image section using jQuery plug-in In this section, you will learn how to zoom an image section by hovering mouse on it using jQuery. The plug-in ,we are using here, is "zoom.js". For zooming an image you must have
Image slider in JQuery
Image slider in JQuery  Hi sir I want to create a image slider in jQuery. Please tell me the name of the best image slider plug-in available. Mention code with your reply
The animation of image using the 'animate' effect of jQuery
The animation of image using the 'animate' effect of jQuery... to animate Image. In this example , we are animating a image using animate function of jQuery. We can do following things during animation using it's
Animate image in jQuery
jQuery provides several methods to implement different kinds of effects in a simple HTML page. jQuery is basically a JavaScript library that simplifies the JavaScript work. Here we takes a small example, that will resize the image
create dynamic image gallery jquery
create dynamic image gallery jquery  How to create a dynamic image gallery in Jquery
Crop Image using plug-in ,JSP and 'Servlet'
Crop Image using plug-in ,JSP and 'Servlet' In this tutorial, we will crop image using jQuery plug-in & servlet. In this example, a image &... selection' effects are implemented by the jQuery. And the cropping of image
jQuery image replacement by click or select
jQuery image replacement by click or select In this section, you will learn to replace image by button click or select drop down without refreshing complete page. EXAMPLE In the given below code, you will learn to replace image
Vertical news slider using jquery
Vertical news slider using jquery  how to creatw vertical news slider using jquery Sorry for wrong category but i cant get my jquery category
Replace a String with another using "fn:replace" tag of JSTL
Replace a String with another using <fn:replace> tag of JSTL In this Section, we will replace a String with another string using <fn:replace> tag... with other string/substring using the <fn:replace> tag of JSTL. This takes
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
Show Limited Data Using jquery
Show Limited Data Using jquery  How to show limited results in JQuery... it using JQuery?   See the JQuery example to show the limited fetch results in JQuery. var comments = $('.description_text').size(); if (comments >
jQuery to Image Magnifier
jQuery to Image Magnifier       In this first jQuery tutorial we will develop a  program that  Image magnifier.ADS_TO_REPLACE_1 Steps to develop the program  
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt (adsbygoogle = window.adsbygoogle || []).push({}); 1 abc bangalore 2 def adfsdf 3
jQuery to Auto Image Scroller
jQuery to Auto Image Scroller       In this first jQuery tutorial we will develop a  program that auto image scrollerADS_TO_REPLACE_1 Steps to develop the program
maximize an image using javaScript
maximize an image using javaScript  Write the code to maximize an image using javaScript
jQuery to Vertical Image Scroller
jQuery to Vertical Image Scroller       In this first jQuery tutorial we will develop a  program that vertical image scrollerADS_TO_REPLACE_1 Steps to develop the program
jQuery to Simple Image Scroller
jQuery to Simple Image Scroller       In this first jQuery tutorial we will develop a  program that simple  image scrollerADS_TO_REPLACE_1 Steps to develop the program
Html form validation using jquery
Html form validation using jquery  Hi i am using form with html. Form elements like textbox, radio,checkbox,listbox i was used now how to validate the elements using submit jquery option
HTML form validation using jquery
HTML form validation using jquery  Is there any way for validating html elements common under a class by giving its class name in jquery validation code..that means validating all elements by using its class name if those
insert image using hibernate
insert image using hibernate  Sir, Today I hadposted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me
Using the jQuery Transform plug-in(XSLT)
Using the jQuery Transform plug-in(XSLT)       Using the jQuery Transform plug-in(XSLT... Language Transformations ). The jQuery Plugin we are using
Image using Java coding
Image using Java coding  Hai, Display image in pdf file using Java coding through Xsl file.. Please help me.. xsl file generate the pdf file
How to change the color of a base64-encoded png image JQuery?
How to change the color of a base64-encoded png image JQuery?  I am going to change the colors of the pixels of a png image(which is in base64 format). This is my source code: var myImg = new Image(); myImg.src = <...>
About search and replace contains of .doc or .docx file using java.
About search and replace contains of .doc or .docx file using java.  Hi , I am trying to replace contents of ms.word document in .doc or .docx... any one tell me how could I replace them using java
Disabling submit button using jQuery
Disabling submit button using jQuery  Hello Sir I want to know - is there any way or approach to disable client side form's "Submit" button. Please give code also.ADS_TO_REPLACE_1   For all submit buttons, via JQuery
display image using jsp
display image using jsp  display image using jsp and phonegap on emulator of eclipse   Here is a simple jsp code that displays an image on browser. <%@ page import="java.io.*" %> <%@page contentType="image/gif
Hide/show Image by click
Hide/show Image by click In this tutorial ,we will discuss about how to display image by click using jQuery. In the below example, a image and two lines are given. By clicking on upper line , it will hide the image and the line
application using AJAX and JQuery and also use JSP
application using AJAX and JQuery and also use JSP   i need create an application using AJAX and JQuery and also use JSP
Image name,image path into database and image into folder using jsp
Image name,image path into database and image into folder using jsp  How to insert image path and image name into oracle database and image into folder using jsp
Using the jQuery event object
Using the jQuery event object       Using the jQuery event object JQuery... to these standards, this system normalize the event object. jQuery. Event
Form validation Using Jquery Plugin
Form validation Using Jquery Plugin  Hello sir I want to implement form validation using JQuery Plug-in. My code is : <html> <style type...;/form> </body> </html> Please provide me JQuery code regarding
Find Browser & it's version using jQuery
Find Browser & it's version using jQuery  Hi sir I heard that JQuery have some method which can be used to find the Browser name & its version. I need the code which checks the browser and if it is "Mozilla", it will show
How to write a search functionality using javascript/jquery
How to write a search functionality using javascript/jquery   How to write a search functionality using javascript/jquery for ex: im searching "s" names it wil display "s" names
Uploading image using jsp
Uploading image using jsp  how to upload image using jsp. Already i tried, But that image file does not read. It returns only -1 without reading that image file ... I want know that solution using by u... Thanks, P.S.N.  
Using the QUnit to test jQuery application
Using the QUnit to test jQuery application       Using the QUnit to test jQuery application Using Qunit , testing of JQuery become very easy and efficient
download image using url in jsp
download image using url in jsp  how to download image using url in jsp
Test hidden element using JQuery
Test hidden element using JQuery  Suppose i have an element which i am hiding and showing, using .hide(), .show() or .toggle().How do you test to see... using following code snippet :ADS_TO_REPLACE_1 $(element).is(":visible") Hope
Implementing Digits restriction Using JQuery
Implementing Digits restriction Using JQuery  Hi Sir I have following field in my html form : <div>Age<input type="text" name="quantity.... Please provide code.   You can implement these two things using ASCII code
Displaying image using jsp and spring.
Displaying image using jsp and spring.  how to display an image stored in WEB-INF/images folder on the browser using jsp and spring
check username availability using JSP & JQuery
check username availability using JSP & JQuery  Hi sir I want check username availability using JSP & JQuery. Please add code with your answer. Thnks in advance
upload image using JSP Hibernate
upload image using JSP Hibernate  sir, I want to take image from user and save to database(MYSQL) using Hibernate and JSP Thanks in advance
image store in oracle using jswing
image store in oracle using jswing  hello ,ihave searched the image store in oracle using jswing but i did not find the code please help me
Auto grow Text Area using jQuery plug-in
Auto grow Text Area using jQuery plug-in  Hi sir How can we make a textarea auto grow ? What is the name of the plug-in used for auto grow text area. Please mention code with your reply
jquery highlight textbox using jQuery
Content highlighting using jQuery In this section , you will learn how to highlight input row or group of input row using jQuery. In the below given example...;Content highlighting in form using jQuery - Example</title> <style>
highlight words in an image using java
highlight words in an image using java  Hai all,In my application left side image is there and right side an application contains textboxes like... want to highlight name in the image using java/jsp/javascript.please help me
How to Store Image using JSF
How to Store Image using JSF  Hi How to upload images in db. using jsf. For jsf photo uploading .. I used this one code for upload image.. But this code haven't option to upload any images . i want to store image in db
Hide hyperlink using jQuery
Hide hyperlink using jQuery In this tutorial, we will discuss about how to hide hyperlink after clicking it using jQuery. In the below example , a hyperlink "Click here to hide this link" is included in the web page. When we
Getting the ID of the element that fired an event using JQuery
Getting the ID of the element that fired an event using JQuery  Hello sir I want to know-Is there any way to get the ID of the element that fires... friend In jQuery event.target always refers to the element that triggered

Ads