jQuery insertAfter() Method

jQuery insertAfter() method inserts HTML elements after the selected elements.

jQuery insertAfter() method and after() method perform the same function. There is one major difference is in the syntax, placement of the content and target element.

Use the insertBefore() method to insert HTML elements before the selected elements.


Here is a syntax for insertAfter() method

Parameter Type Description
content String Required Specifies the HTML content to insert.
selector Selector Required Specifies the selector expression, where to insert the content.


Here, in this example insertAfter() method apply on selected elements when click on button.

<!DOCTYPE html>
  <title>jQuery insertAfter() method</title>
  <script src="jquery-latest.min.js"></script>
        $("<p>New text come after end of selected element.</p>").insertAfter("p");
    <p>First paragraph start here...</p>
  <button>Click Me</button>

Run it...   »