-2

I'm making an auto image slider and this is my html and js:

<div class="navigation-manual">
      <label for="radio1"></label>
      <label for="radio2"></label>
      <label for="radio3"></label>
      <label for="radio4"></label>
    </div>

    <script>
      var counter=1;
      setInterval(function(){
        document.getElementById('radio' + counter).checked = true
        counter++
        if(counter>4){
          counter=1
        }
      }, 5000)
    </script>

I don't really understand why you have to add counter into "document.getElementById('radio' + counter)" like this and what does the check "checked" do...i'm just a beginner and i don't really understand the whole Javascipt. Can anyone explain it for me? Thank you so much

suga sunshie
  • 107
  • 2
  • 7

1 Answers1

0

The HTML should have radio buttons first because that is what you are applying label to and the code is incomplete. Giving the below comments just based on general understanding.

  • The counter is keeping track of the currently active radio button.
  • The checked attribute is for the radio buttons. Here based on the counter you are selecting the radio button based on which the image would be selected.
vickybits
  • 1
  • 2