Javascript examples for jQuery Method and Property:appendTo
The appendTo() method inserts HTML elements at the end of the selected elements.
If content is an existing element, it will be moved from its current position, and inserted at the end of the selected elements.
Parameter | Require | Description |
---|---|---|
content | Required. | HTML tags content to insert. |
selector | Required. | on which elements to append the content to |
The following code shows how to Insert a <span> element at the end of 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>").appendTo("p"); });/*from ww w .j ava 2s. c om*/ }); </script> </head> <body> <button>Insert span element at the end of each p element</button> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html>