jQuery scroll radio input into div to checked by default

Viewed 119

I've a DIV (overflow-y:auto;) with some RADIOs input, and a radio checked by default.

How do I scroll automatically to the radio CHECKED?

The DIV is scrollable and shows radio four at a time.. Is it possible to scroll and show automatically radio checked, in the example "SEVEN", by default?

  1. ONE
  2. TWO
  3. THREE
  4. FOUR
  5. FIVE
  6. SIX
  7. SEVEN (checked by default)
  8. EIGHT
  9. NINE

Thanks!

1 Answers

you should give the radio button an id or class , something to identify it with, then you can do like this :

$('html, body').animate({
    scrollTop: $("#defaultRadio").offset().top //let's say your radio button has id="defaultRadio"
}, 1000);

this will do an animation of 1000 milliseconds ( 1 second ) towards your target div

Related