View Single Post
Old 08-28-2016, 04:09 PM  
2MuchMark
Videochat Solutions
 
2MuchMark's Avatar
 
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 48,540
Question for the HTML5 Brainiacs of GFY

Greetgins and salutations!

I have a question for the HTML5 gurus:

How can I display a default image in HTML5 if the image I want is not available?

Here's a piece of code:

<div style="background-image: url(images20/intro.jpg);">

But in certain circumstances, the file named intro.jpg will not always exist. So when this file does not exist, I want it to load a different image. For example, default.jpg

I can do this already with a standard IMG tag, like this:

<img id="currentPhoto" src="intro.jpg" onerror="this.src='Default.jpg'">

But how do I do it when using a background image in a div?
__________________

VideoChat Solutions | Custom Software | IT Support
https://www.2much.net | https://www.lcntech.com
2MuchMark is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote