Just Wondering Just Wondering - 5 months ago 7x
Javascript Question

How do I delete an image element if it's source file doesn't exist

I am making a site with a popup. The popup is supposed to have up to 12 images in it. I am calling my images pizza1.jpg, pizza2.jpg, pizza3.jpg, and so on.

Is there any way with pure JavaScript to make the images show up only if there is actually a file with the name I have told it to look for?

W92 W92

You can use onError event for remove object from your popup:

<img src="src" onError="removeElement(this);" />

Check if it will work:

function removeElement(element) {