Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • 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.


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

$( 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!