Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rajucs/0cfde6552ce8ae6d463aea2c0830ee57 to your computer and use it in GitHub Desktop.

Select an option

Save rajucs/0cfde6552ce8ae6d463aea2c0830ee57 to your computer and use it in GitHub Desktop.

Revisions

  1. rajucs created this gist Aug 17, 2023.
    18 changes: 18 additions & 0 deletions Scrolling to a Specific Div After an Ajax Call using jQuery
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    // Perform your Ajax call here
    $.ajax({
    // ... your Ajax settings ...
    success: function(response) {
    // After the Ajax call is successful and content is loaded
    // Scroll to the target div with animation
    $("html, body").animate(
    {
    scrollTop: $("#wps-comment-list").offset().top - 50
    },
    2000 // Animation duration in milliseconds
    );
    },
    error: function(error) {
    // Handle Ajax error
    console.error("Ajax call error:", error);
    }
    });