JSFiddle - React, Tailwind, and code Playground

HTML

<div id="content">
  
</div>

JavaScript

var text = "";
for (var i=0; i<100; i++) {
  text += i + "<br>";
  if (i == 50)
    text += "<button>add content above</button><br>";
}
$("#content").html(text);

$("button").click(function() {
  //cache the org height
  var orgHeight = $("#content").height();
  //run your ajax request.
  mockAjax(function() {
    //in the callback ajust the height
    $(window).scrollTop($(window).scrollTop() + $("#content").height() - orgHeight);
  });
});

function mockAjax(callback) {
  $("#content").prepend("<div>this<br>is<br>new<br>content</div>");
  callback();
}