Share on Google+Share on Google+

samar
Replace broken Image using JQuery
2 Answer(s)      6 years and 4 months ago
Posted in : JavaScript Questions

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

Ads

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...', 'missing.jpg'); } }); }) This code will replace the broken image
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
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
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
create dynamic image gallery jquery
create dynamic image gallery jquery  How to create a dynamic image gallery in Jquery
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
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
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
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
Broken link list
Broken link list   Please provide me a java code to find the broken link list of url's for a given url
jQuery to Image Magnifier
jQuery to Image Magnifier       In this first jQuery tutorial we will develop a  program that  Image magnifier. Steps to develop the program  Step 1: Create
jQuery to Auto Image Scroller
jQuery to Auto Image Scroller       In this first jQuery tutorial we will develop a  program that auto image scroller Steps to develop the program  Step 1
jQuery to Vertical Image Scroller
jQuery to Vertical Image Scroller       In this first jQuery tutorial we will develop a  program that vertical image scroller Steps to develop the program Step 1
jQuery to Simple Image Scroller
jQuery to Simple Image Scroller       In this first jQuery tutorial we will develop a  program that simple  image scroller Steps to develop the program Step 1
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
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
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 >
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 = <...>
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
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
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
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
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
maximize an image using javaScript
maximize an image using javaScript  Write the code to maximize an image using javaScript
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.   For all submit buttons, via JQuery, it'd
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
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
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads