jQuery insertAfter Method


jQuery insertAfter method : This is used to insert new html element(content) After the specified element. If You want to add some content after a specified element use the jQuery insertAfter Method. The $(content).insertAfter(selector) is used to select and insert content.


Syntax for jQuery insertAfter

Here is syntax to add content(insertAfter) after selected element using jQuery-

$(content).insertAfter(selector);

jQuery insertAfter Method

jQuery insertAfter() Method – Example –

<script type="text/javascript">
         $(document).ready(function(){ 
              $( "#afterExample" ).on( "click", function(event) {             
                $("<p><span>Insert After All '<div>' Tag</span></p>").insertAfter("div");               
              });
               
          });
</script>

Try it »

The above code will produce following result-

Note : This is screenshot of the output. To run this demo click on the above “Try it” button.

jQuery insertAfter Method


Advertisements

Add Comment

📖 Read More