Search code examples
jquerycssradio-buttoncycle

Cycle radio buttons


I would like to cycle through 3 radio buttons (as seen below) with a 5 second delay between each selection change. What is the best way to approach this? The reason I require this is because I am using these radio buttons as my navigation for a slideshow.

  <input type="radio" name="myImages" id="cover1" checked />
                <input type="radio" name="myImages" id="cover2" />
                <input type="radio" name="myImages" id="cover3" />

Any help would be much appreciated thanks!


Solution

  • Here is a basic example of how to do what you asked with jQuery:

    $(function(){
      var id = 1;
      window.setInterval(function(){
        $( "#cover" + id ).prop( "checked", true );
    
        if (id == 3) {
            id = 1;
        }
        else {
            id++;
        }
    }, 5000);
    })