Javascript examples for jQuery Method and Property:after
The after() method inserts content after the selected elements.
$(selector).after(content,function(index));
Parameter | Require | Description |
---|---|---|
content | Required. | HTML content or jQuery DOM elements to insert |
function(index) | Optional | a function that returns the content to insert |
The following code shows how to Insert content 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(){ $("p").after("<p>Hello world!</p>"); });//from w ww . j a va2 s . c o m }); </script> </head> <body> <button>Insert content after each p element</button> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html>