Javascript examples for jQuery Method and Property:after
Add element returned from a function using after()
<!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(function(n){ return "<div>index " + n + ".</div>"; });//from ww w . j a va 2s . c o m }); }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <p>This is another paragraph.</p> <button>Insert after each p element</button> </body> </html>