Here we are going to see how we can add a new element into the body of the page or inside particular div using jQuery. We have a function called append() in jQuery to do this trick.
See the below examples, This example shows how you can append a new HTML element into the body of the page:
EXAMPLE 1: Append an HTML element when page loads
$(document).ready(function() { $("body").append('This div is added through jQuery after the page loaded'); });
EXAMPLE 2: Create an HTML Element after clicking a selector (here a tag):
$(document).ready(function(){ $("#addnew").click(function(){ $("body").append('This div is added through jQuery after the page loaded'); }); });