w3resource

jQuery: Fix broken images automatically

jQuery Practical exercise Part - I : Exercise-5

Fix broken images automatically.
Hide the following broken img tag in the body section.

Sample Data :

<body>
<a href="https://www.w3resource.com"><img src="//www.w3resource.com/image/w3resourcelogo.gif" alt="w3resource logo" width="150" height="78" /></a> </body>

Sample solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>Fix broken images automatically</title>
</head>
<body>
<a href="https://www.w3resource.com/images/w3resource-logo.png" alt="w3resource logo" width="150" height="78" onerror='$(this).hide();'/></a>
</body>
</html>

See the Pen jquery-practical-exercise-5 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Disable/enable the form submit button.
Next: Blink text using jQuery.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.