jQuery insertAfter()

The insertAfter() method inserts HTML elements after the selected elements.To insert HTML elements before the selected elements, use the insertBefore()  method.


Syntax:

$(content).insertAfter(selector)


Example:

<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script>
$(document).ready(function(){
    $("button").click(function(){
        $("<span>Hello world! How are You ? </span>").insertAfter("p");
    });
});
  </script>
</head>
<body>
  <button>Insert span element after each p element</button>
  <p>This is a paragraph.</p>
  <p>This is another paragraph.</p>
</body>
</html>