The Wayback Machine - https://web.archive.org/web/20240118165134/https://www.geeksforgeeks.org/how-to-insert-a-jquery-object-after-all-paragraphs-using-jquery/
Open In App
Related Articles

How to insert a jQuery object after all paragraphs using jQuery ?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The task is to insert a jQuery object after all the paragraphs using jQuery.

Approach:

  • Create DOM element or jQuery object using <span> tag.
  • Create a paragraph using <p> tag.
  • Create a button using button tag after clicking on which the object will be inserted after paragraph.
  • Write a script that will call a function jQuery.after()  which is used to insert a jQuery object after all the paragraphs.

Example: Below is the working code using the above-mentioned steps.

HTML




<!DOCTYPE HTML>
<html>
  
<head>
  <script src=
  </script>
</head>
  
<body>
  <h1 style="color:green"> 
     GeeksforGeeks 
  </h1>
  
  <span>
     Dom element / jQuery object
  </span>
  
    
<p>
     This is paragraph
  </p>
  
  
  <button id="GFG_button1" style="display: block;
     margin-top: 15px;">
     Click here to insert object after paragraph
  </button>
  
  <script>
      $('#GFG_button1').click(function () {
          $("p").after($("span"));
      });
  </script>
</body>
  
</html>


Output:

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 22 May, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials