Skip to content
Related Articles

Related Articles

How to insert a DOM element after all paragraphs using jQuery ?

View Discussion
Improve Article
Save Article
  • Last Updated : 31 Dec, 2020

In this article, we will insert a DOM element after all paragraph elements using jQuery. To insert a DOM element we use after() and createTextNode() methods. The createTextNode() method is used to create a TextNode which contains an element node and a text node. It is used to provide text to an element. The after() method is used to insert the specified content after each selected element.


$( selector ).after( content );



<!DOCTYPE html>
    <!-- Import jQuery from CDN library -->
    <script src=
        $(document).ready(function () {
            $("button").click(function () {
                    .createTextNode("Hello World!"));
<body style="text-align: center;">
    <h1 style="color: green;">
        How to insert a DOM element after
        all paragraphs using jQuery?
        GeeksforGeeks computer
        science portal
    <button>Click Here!</button>


Before clicking the button:

After clicking the button:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!