Collapse img tag when src path is wrong in XHTML1.0

131 Views Asked by At

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

1

There are 1 best solutions below

0
On

@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>