jQuery insertAfter()
jQuery insertAfter()
is a jQuery method that allows you to insert HTML content or an existing HTML element after another HTML element.
Syntax
The syntax for insertAfter()
is as follows:
$(content).insertAfter(target)
Here, content
is the HTML element or content that you want to insert after the target
element.
Use
The insertAfter()
method is useful for dynamically adding content to your web page. It allows you to specify the location where the content should be inserted and can be used to move elements as well.
Example
Here, we have a basic HTML page where we want to move a <p>
tag after a <div>
tag using insertAfter()
: