How do I make a jQuery loop which changes the href attribute of a link?

I've built a slideshow gallery from scratch using jQuery. It can have any number of slides. Under the slideshow I have a 'More info' button. I would like this link to change every 5000ms to reflect the slide being show.

I know I can use .attr to change the href value itself, it is just changing it at intervals of 5000ms to different things (on a loop!) that I'm completely at a loss with...

Help would be greatly appreciated!

Answers


Use a timer.

//Set Image to first picture by default.
$('#yourImageId').attr("src", imageSrcArray[0]);

var milliseconds = 5000;

//Call Function after 5 seconds to show second picture
var t=setTimeout("changeSlide();", milliseconds); 

//If you set the image's original src to your first array item, this will cause the first update in 5 seconds to display the second item.
var cnt=1; 

function changeSlide(){

    //update image src
    $('#yourImageId').attr("src", imageSrcArray[cnt]);

    t=setTimeout("changeSlide();", milliseconds);//Call Function Again after 5 seconds

    cnt++;

    //Check that cnt is within image array bounds
    if (cnt > imageSrcArray.length-1) cnt=0;

}

Need Your Help

How to allow users to pick dates using Python

date datetime python-2.7 datepicker

I'm new to Python and have searched everywhere for days for this solution, so I apologize in advance if the answer is posted somewhere that I've not been able to find. Nothing I find addresses this

Video Not Playing Good In IE

video html5-video flash-player mp4 video.js

Hi I Have a video here playing good in IE and Mozilla, but when I open the page in IE and played the video.. the video is not playing well as the video playing in chrome? Am I missing something? Th...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.