If you are only handling scrolling to an input element, you can use focus()
. For example, if you wanted to scroll to the first visible input:
$(':input:visible').first().focus();
Or the first visible input in an container with class .error
:
$('.error :input:visible').first().focus();
Thanks to Tricia BallTricia Ball for pointing this out!