Scott Hunter Scott Hunter - 6 months ago 23
jQuery Question

Scroll modal to top after clicking navigation

i have the following code which loads wordpress posts into a modal which works great. The only problem is that when one of the nav links are clicked it loads the next post without scrolling to the top.

Is there any way i can make the modal scroll to the top when one of the nav links are clicked ?

(function($) {
$(document).on("click", ".esg-grid a, .postmodal .post-navigation a", function(event) {
var post_url = $(this).attr("href");
var post_id = $(this).attr("rel");
$(".postmodal").load(post_url + " #main-content" );
//window.history.pushState("object or string", "Title", "/new-url");
return false;




This should scroll to the top of your modal. You can put it right after your load in the click listener to get it to scroll.