I want the selected option to appear in the middle of the drop-down list. When I first load the page, it appears at the bottom of the drop-down list, but if I scroll through it and exit, she remembers that when I open it again. I want it to appear in the middle by default.
At first I thought I could just use javascript to select an option past the one I want, and then return it to the correct option. I played with scrollTop and scrollTo, but none of them seemed to give me what I needed. I tested it in Chrome, but it should also work in Firefox and IE. Any ideas?
Edit: I tried the scrollTo plugin, but it does not work for dropdowns. Take a look at these code snippets
From HTML:
<select id="test"> <option>1</option> <option>2</option> // ........ <option selected="selected">21</option> <option>22</option> // ........ <option>40</option> </select>
From Javascript:
$(function() { alert( $('#test option:selected').next().text() ); // alerts 22 $().scrollTo('#test'); // scrolls the screen to the drop-down $('#test').scrollTo( $('#test option:selected').next() ); //does nothing });
source share