0
votes

I have a jQuery slideshow that displays a caption over each slide by taking the text from the image's alt and title text. The only problem is I don't want it to display the caption at all when an image in the slideshow doesn't have a title/alt.

See the example code here: http://jsfiddle.net/MCdyC/

I know I need to have an IF statement test to see if the image title/alt is blank, but nothing I try has worked.

2
When you say "don't display the caption at all when doesnt have a title", are you referring to not showing that dark gray bottom bar?Tina CG Hoehr

2 Answers

1
votes

Try something along the lines of:

var title = $('.showimage').attr('title');
var alt = $('.showimage').attr('alt');

if (typeof title !== 'undefined' && title !== false && typeof alt !== 'undefined' && alt !== false)​ {

    // WRAP YOUR WHOLE FUNCTION IN HERE

    } else {

    // WRAP YOUR WHOLE FUNCTION IN HERE WITHOUT THE SHOW CAPTION FUNCTION

}​
1
votes
if($('ul.slideshow li.show').find('img').attr('title')!="")
{
    $('#slideshow-caption h3').html($('ul.slideshow li.show').find('img').attr('title'));
}

Here is some sample snippet to get you started.