Javascript examples for jQuery Method and Property:append
The append() method inserts specified content at the end of the selected elements.
$(selector).append(content,function(index,html));
Parameter | Require | Description |
---|---|---|
content | Required. | HTML elements/jQuery objects/ DOM elements to insert |
function(index,html) | Optional. | a function that returns the content to insert |
The following code shows how to Insert content at the end of all <p> elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("p").append(" <b>Appended text</b>."); });//from w w w. j a va 2 s .c o m }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button id="btn1">Append text</button> </body> </html>