Search code examples
jqueryajaxinsertafter

Use .insertAfter with the response from an ajax call


I have a basic dom

<div class="outer">
     <div class="inner"></div>
</div>

And an ajax call

$.ajax({
     ...
     ...
     success: function(html) {
         //insert 'html' after '.inner'
     }

I can't use append here because there will be items after'inner' so I need to insert 'html' specifically after 'inner' but I'm not sure how to use the 'html' with 'inserAfter' here.


Solution

  • Try the following:

    $(".inner").after(html);
    

    Just be aware, in case you have the class at multiple locations, it will add the html at each location.