Search code examples
jqueryjquery-pluginsjcarousel

Using jcarousel, how can I get the image alt to display in an external div#caption


I am using: http://sorgalla.com/projects/jcarousel/#Configuration

And I am implementing this locally to prove functionality before I load it into a site. My current setup is:

<script type="text/javascript">
function mycarousel_initCallback(carousel) {

jQuery('#mycarousel-next').bind('click', function() {
    carousel.next();
    return false;
});

jQuery('#mycarousel-prev').bind('click', function() {
    carousel.prev();
    return false;
});
};

jQuery(document).ready(function() {
jQuery("#mycarousel").jcarousel({
    scroll: 1,
    visible: 1.1,   
    initCallback: mycarousel_initCallback,
    buttonNextHTML: null,
    buttonPrevHTML: null,
    itemLoadCallback: trigger
});
});
function trigger(carousel, state)
{
$("#counter").html(carousel.first);  
}
</script>
<div id="clip">

<ul id="mycarousel">
    <li><img src="images/bda_1.jpg" alt="Alt Tag 1" width="638" height="358"/></li>
    <li><img src="images/bda_2.jpg" alt="Alt Tag 2" width="638" height="358" /></li>
    <li><img src="images/bda_3.jpg" alt="Alt Tag 3" width="638" height="358" /></li>
    <li><img src="images/bda_1.jpg" width="638" height="358" /></li>
</ul>

</div>
 <a href="#" id="mycarousel-prev">&laquo; Prev</a>
 <a href="#" id="mycarousel-next">&laquo; NEXT</a>

<div id="counter"></div>

<div id="caption"></div>

I know I can use a callback but my js/jquery is to beginner to get it done. I simply want to pull the alt tag out and display it in the div#caption

thanks for the help.


Solution

  • In the jcarousel main loop (which I don't see in your code) you'd so this:

    $('#caption').html($('mycarousel').find('img').eq(COUNTER).attr('alt'))
    

    Where the value of COUNTER comes fom you'll have to find in the script. If there's a callback for this function you could put it there.