0

I run a function when i click a anchor tag.

$("#addItemMedicine")
.click(function () {
   $.get("/Referred/AddMedicineNewRow",
    function (data) {
     $("#MedicineEditorRows").append(data);
    })
   .fail(function (xhr, err) {
  alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
                        alert("responseText: " + xhr.responseText);
                    });
            });

When run this function , Scroll Automatically to the top of the Page.

ar.gorgin
  • 4,765
  • 12
  • 61
  • 100

1 Answers1

0

You can use scrollIntoView. Just select one of your existing elements, or add fictional.

function scrollToTop() {
    $('body').append($('<div id="zero" style="position:absolute;opacity:0;left:0;top:0"></div>'));
    $('#zero')[0].scrollIntoView();
    $('#zero').remove();
}
2oppin
  • 1,941
  • 20
  • 33
  • thanks, I can change scroll position to my elemnt after run function, but i want to stop scroll. – ar.gorgin Jul 01 '18 at 06:34
  • It's not obvious from your post . how to stop scroll ~ https://stackoverflow.com/questions/14185974/how-to-prevent-jump-on-an-anchor-click – 2oppin Jul 01 '18 at 13:58