Scrolling to the top of a popup with jQuery

I have a popup and it has a PopupDiv id in it and I want to scroll to the top address after an Ajax request made to the controller returns (when there is an error, I return a message with Json and I show it to the popup). I found many different ways online and tried the methods below, but none of them work (they work a whole page, not a popup). Any idea?

View:

<div id="PopupDiv" style="height: 421px; overflow-y: scroll; margin-top: -7px; margin-bottom:-14px ">

<script>
$.ajax({
        type: "POST",
        url: '@Url.Action("Create", "Issue")',
        data: formdata,
        dataType: "json",
        processData: false,
        contentType: false, 
        success: function (response) {
        if (!response.success) {

        //I tried the following by one by one, but none of them is working:
        messageThread.scrollTop = messageThread.scrollHeight;
        $('html, form').animate({ scrollTop: $('#PopupDiv').position().top }, 'slow');          
        $(window).scrollTop(300);
        $("html, body").animate({ scrollTop: "1024px" }, 5000);
        var objDiv = document.getElementById("#PopupDiv");
        objDiv.scrollTop = objDiv.scrollHeight;
        }
    }
});
</script>

      

+3


source to share





All Articles