JulianJ
JulianJ

Reputation: 1317

Fullcalendar syntax

I'm using Fullcalendar and it works great. I have got it to show images for different events but I want to add a line of code that displays a placeholder image if no image is correct. For some reason I'm doing something wrong with the syntax I'm sure. Can anyone tell me what I'm doing wrong?

This works

eventRender: function (event, element) {
var correctimg = '<div><img src="imageFiles/' + event.id + '/pic1.jpg" width=\"100\" class=\"img-thumbnail\"></div>'

                element.popover({
                    placement:'top',
                    html:true,
                            image:true,
                    trigger : 'hover',
                    animation : 'true',
                            title: event.firstname +" "+ event.lastname,
                    content: correctimg,
                            container:'body'


                });

I want to add

onerror="this.src='no_photo.jpg'"

But this does not work

var correctimg = '<div><img src="imageFiles/' + event.id + '/pic1.jpg" width=\"100\" class=\"img-thumbnail\" onerror=\"this.src='no_photo.jpg'\"></div>'

Upvotes: 0

Views: 116

Answers (1)

jozzy
jozzy

Reputation: 2943

You can add a global function and then call it

function setImg(elem,src){

   elem.src = src;
}

and add onerror="setImg(this,'no_photo.jpg');";

Upvotes: 1

Related Questions