Javascript examples for jQuery Method and Property:insertAfter
The insertAfter() method inserts HTML elements after the selected elements.
For an existing element, it will be moved from its current position, and inserted after the selected elements.
Parameter | Require | Description |
---|---|---|
content | Required. | HTML tags to insert. |
selector | Required. | where to insert the content |
The following code shows how to Insert a <span> element after each <p> element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("<span>new!</span>").insertAfter("p"); });/* ww w.jav a 2 s . c o m*/ }); </script> </head> <body> <button>Test</button> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html>