Iulian Boiculese
Iulian Boiculese

Reputation: 393

scrollTop not working in browsers other than Firefox

The scrollTop function in jQuery for select list is working only in Firefox. In other browsers it's not working.

For example

<select id="mySelect">
<option value="1">1</option>
<option value="2">2</option>
...
<option value="100">100</option>
</select>

$('#mySelect').click(function(){
         $(this).scrollTop(150);
});

Does anybody know how to resolve this problem so it works across all browsers?

Upvotes: 1

Views: 738

Answers (2)

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try this

$('#mySelect').click(function(){
    var $options = $(this).find("option");
    $options.eq(($options.length)/2)[0].selected = true;
});

Upvotes: 1

Seth
Seth

Reputation: 6260

It could be that the select box doesn't support a click event in some browser? I'm assuming you want the browser to scroll to the that section of the page and then let them make a selection. You could try a change or focus event instead.

Upvotes: 0

Related Questions