jquery, how to scroll the selected option in visible view?

advertisements

Here I created a sample to help me be understood, http://www.jsfiddle.net/BLvsF/

I want the item-'a6' to be scrolled into the visible select box, how can I make it? I'd like to use jquery to do same as

$(document).ready(function() {
    $('#btn').click(function() {
        document.getElementById('a6').scrollIntoView();
        });
});

but, how to implement the same using jQuery?

I tried using .get(0).scrollIntoView(). but still not applicable.

$(document).ready(function() {
    $('#btn').click(function() {
        $('#a> option:selected').clone(false).appendTo('#b').get(0).scrollIntoView();
    });
});

http://www.jsfiddle.net/CYQfD/

Thanks, Elaine


just replace the button handler with this line of code, and you are done.

$('#a').val('a6').scrollIntoView();