How to create a div element in jQuery ? Last Updated : 17 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report There are various method to create HTML element inside an HTML document using JQuery. But the simplest of all is append() and prepend() method. Method 1: Using prepend() Method: The prepend() method is used to insert a specified content at the beginning of the selected element. Example: This example uses prepend() method to create div element at the beginning of selected element. html <!DOCTYPE html> <html> <head> <title>Create div element</title> <script src=" https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <!-- Script to add div element in the HTML document --> <script> $(document).ready(function() { // Select the element inside div // element will be added $("body") .prepend('<div class="added">This is added div </div>'); }); </script> <!-- Style to use on div element --> <style> div { padding: 20px; margin-bottom: 10px; border: 1px solid green; display: inline-block; } </style> </head> <body> <div class="initial"> This is initial div </div> </html> Output: Method 2: Using appendTo() Method: The appendTo() method in jQuery is used to insert HTML element at the end of the selected element. Example 1: This example uses appendTo() method to create div element at the end of selected element. html <!DOCTYPE html> <html> <head> <title>Create div element</title> <script src=" https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <!-- Script to add div element at the end of document --> <script> $(document).ready(function() { $("<div>This is another added div</div>").appendTo("body"); }); </script> <!-- Style to use on div element --> <style> div{ padding: 20px; margin-bottom: 10px; border: 1px solid green; display: inline-block; } </style> </head> <body> <div class="initial"> This is initial div </div> </body> </html> Output: Example 2: This example uses appendTo() method to create div element within the div element. html <!DOCTYPE html> <html> <head> <title>Create div element</title> <script src=" https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <!-- Script to create div element --> <script> $(document).ready(function() { jQuery("<div/>", { id: "div-id", class: "div-class", text: "This is text of div" }).appendTo(".box"); }); </script> <!-- Style to add on div element --> <style> div { padding: 20px; margin-bottom: 10px; border: 1px solid green; display: inline-block; } </style> </head> <body> <div class="initial"> This is initial div </div> <div class="box"></div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to create a div element in jQuery ? P Pankaj_Singh Follow Improve Article Tags : Web Technologies JQuery Similar Reads Create a Div Element using jQuery In this article, we will see how to create a <div> element using jQuery. We can create a div element with the following steps: Steps to Create a Div ElementCreate a new <div> element.Choose a parent element, where to put this newly created element.Put the created div element into the par 2 min read How to create an HTML element using jQuery ? In this article, we will see how to create an HTML element using jQuery. To create and append the HTML element, we use the jQuery append() method. The jQuery append() method is used to insert some content at the end of the selected elements. Syntax: $(selector).append( content, function(index, html) 2 min read How to select elements by attribute in jQuery ? jQuery is a lightweight JavaScript library. In the vanilla JavaScript language, the getElementById method is used to select an element. However, jQuery provides a much lighter alternative for the same purpose. The 'jQuery Selector' allows the user to manipulate HTML elements and the data inside it(D 2 min read How to move one DIV element inside another using jQuery ? In this article, we will learn to move one HTML div element inside another using jQuery. The HTML div element is used to define a division or a section in an HTML document.Method used: parent(): This method is used to get the parent of each element in the current set of matched elements, optionally 2 min read How to Wrap an Element with Another Div Using jQuery? We will see how to wrap an element with another div in jQuery. We will simply wrap an element inside a div tag in jQuery. These are the following approaches: Table of Content Using wrap() method Using wrap.inner() methodApproach 1: Using wrap() method We include the jQuery library in the <head 3 min read Like