Add Captions to jQuery Cycle Slideshows

It is pretty easy to add captions to jQuery Cycle slideshows even though there is no ‘out of the box’ way of doing this. The after option allows you to specify a function to be executed after the slide transition has finished and this is what we will be using to add captions to your slideshow. You simply need to modify your image tags to include a caption for the image and add in a placeholder for the caption to go:

*   ![](img1.jpg)
*   ![](img2.jpg)
*   ![](img3.jpg)
*   ![](img4.jpg)

Then, you can put a simple function in the after option to extract the caption from the visible slide with jQuery and put this into your placeholder:

1
2
3
4
5
$("ul#slides").cycle({
after: function(){
$('#imageCaption').html($('#slides li:visible img').data('caption'));
}
});

This can be easily extended to titles and any other information you need to present with your images. You just put any additional data for the image in to the image tag’s data-attributes and you can access them in the same way:

$('#slides li:visible img').data('your-data-attribute');

You can download the jQuery Cycle plug here