Skip to content
Related Articles
Open in App
Not now

Related Articles

How to insert some HTML after all paragraphs using jQuery ?

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

In this article, we will insert some HTML content after all paragraphs using jQuery. To add some content after all paragraph elements, we use the after() method. This method is used to insert the specified content after each selected element in the set of matched elements.

Syntax:

$( selector ).after( content );

Example:

HTML




<html>
<head>
  <!-- Import jQuery from CDN -->
  <script src=
  </script>
  
  <script>
    $(document).ready(function () {
      $("button").click(function () {
        $("p").after(
          '<p>Welcome to GFG</p>
          <input type="text">'
        );
      });
    });
  </script>
</head>
<body style="text-align: center;">
  <h1 style="color: green;">
    GeeksforGeeks
  </h1>
  
  <h3>
    How to insert some HTML after
    all paragraphs using jQuery?
  </h3>
    
  <p>
    GeeksforGeeks computer 
    science portal
  </p>
  
  <button>Click Here!</button>
</body>
</html>


Output:

Before clicking the button:

After clicking the button:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!