I try to scroll a list made by dynamically. I've found this answer, but it did not help me. I guess that this is because my list is a dynamic list. How can I do? I want to scroll dynamic list on select value.
This is a fiddle with my code: http://goo.gl/Tv7wvj and this is my code
HTML
<div class="scroll order">
<ul></ul>
</div>
CSS
.scroll{
overflow-y: scroll;
width:150px;
height:80px;
}
Javascript
$(document).ready( function() {
var html = '';
for(i=0; i<10; i++){
if(i==6){
html += '<li> <label><input type="radio" name="radio" value="li'+i+'" checked="checked" /> 0'+i+' </label> </li>';
continue;
}
html += '<li> <label><input type="radio" name="radio" value="li'+i+'" /> 0'+i+' </label> </li>';
}
$('ul').append(html);
});
var $s = $('.scroll');
var optionTop = $s.find('[value="04"]').offset().top;
var selectTop = $s.offset().top;
alert("optionTop : "+optionTop+" / selectTop : "+selectTop);
$s.scrollTop($s.scrollTop() + (optionTop - selectTop));