jQuery provides multiple methods to dynamically add new elements to the DOM. These methods allow inserting content inside or around existing elements in real time.
(Inside the box)
// General syntax for adding elements using jQuery
$(selector).append(content);
$(selector).prepend(content);
$(selector).before(content);
$(selector).after(content);
// Buttons dynamically insert elements relative to #demo
$("#demo").append("<p>Appended</p>");
$("#demo").prepend("<p>Prepended</p>");
$("#demo p:first").before("<p>Before</p>");
$("#demo p:first").after("<p>After</p>");
This is a paragraph.
Each button inserts a new paragraph at a different position relative to the selected elements using jQuery DOM manipulation methods.
// appendTo() adds an element into the target container
$("<p>Appended using appendTo</p>").appendTo("#appendToExample");
Target container:
after()prepend()