0

Is it possible to replace a photo with simple text, in case the link is wrong or the photo is no longer available?

<img id="CurrentPhoto" src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Stack_Overflow_logo.svg/1200px-Stack_Overflow_logo.svg.png" onerror="this.src='https://www.stackoverflowbusiness.com/hubfs/logo-so-white.png'" alt="">

With this code it is possible to replace the image in case of broken link. However, I wish I could insert text instead of the second photo. For example, make text "eg Stackoverflow" appear if the first photo is not available.

It's possible? Would any good little angel know how to help me?

2 Answers2

1

Using the alt attribute is a good solution for this, because it is made to be there for displaying when the image is not loaded.

There is already a similar question here on Stackoverflow: How to hide image broken Icon using only CSS/HTML?

The answer is not the accepted answer, but I think it is a very nice way to do this with pure css.

The code is fine and there is also a link if you like to check the source: https://bitsofco.de/styling-broken-images/

rank
  • 2,361
  • 2
  • 10
  • 20
  • Thanks! I try to see and let you know – Gabriele C. May 13 '20 at 22:58
  • 1
    Great! If it solves your problem, you can accept the answer. If you use another code, please share your own solution and accept this, so others who find this question know what worked for your issue if they are looking for something similar. – rank May 13 '20 at 23:11
0

I apologize but I don't know how to open a clarification or modify the initial post.

I try to explain myself better. I would like to make the text appear without the classic icon that appears when the image is not loaded. Only the text.

enter image description here

  • 1
    You can edit your question and delete this post. There should be small links underneath. – rank May 13 '20 at 23:00
  • Thanks! I apologize humbly. I'm new and I had never noticed those little voices. Thanks for your patience – Gabriele C. May 13 '20 at 23:05