0

I have an img tag. When the src path is wrong, I need to collapse the img tag. I can achieve this by using

onerror

in HTML4. However, XHTML1.0 is not allowing the onerror attribute.

How can I achieve this in XHTML1.0?

Thanks in advance

Don
  • 863
  • 1
  • 8
  • 22
Manikandan
  • 673
  • 3
  • 12
  • 26

1 Answers1

0

@Manikandan, I don't get idea how you want to collapse the img tag. but I use the following technique to use onerror with valid xHTML validation to show the default picture if original picture not found using Javascript. See if it can help you.

<img src="sample.gif" alt="Test" id="testimg" />
<script type="text/javascript">

<!--CDATA
document.getElementById("testimg").onerror = function () { this.src='noimage.gif'; };
-->
</script>