How to scroll to the top of a modal window in javascript

To avoid rough movement to the top I would prefer to use (animated movement):

$('#modalId').animate({
        scrollTop : 0
    }, 'slow');

This is a solution without using JQuery, first you get your modal by the id and then, the function scrollIntoView will move to the top of the element you selected, in this case your modal.

let element = document.getElementById('groupModal');    
element.scrollIntoView(true);

To scroll the page to the modal, select html, body and scroll to the offset top of the modal

$("html, body").scrollTop($("#modalId").offset().top);

If you want to scroll the modal div to the top use

$("#modalId").scrollTop(0);

Example on jsFiddle

You can combine both to scroll the page and the modal to a visible area for the user if needed.

References

  • jQuery scrollTop
  • jQuery offset

$('#modalId').scrollTop(0);

scrollTop() only returns the value; scrollTop(0) sets the value to 0 (all the way to the top)