Create a Div Element using jQuery Last Updated : 29 Jan, 2024 Comments Improve Suggest changes Like Article Like Report 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 parent element.Example 1: This example creates a <div> element and uses the append() method to append the element at the end of the parent element. html <!DOCTYPE html> <html> <head> <title> Create div element using jQuery </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <style> #parent { height: 100px; width: 300px; background: green; margin: 0 auto; } #newElement { height: 40px; width: 100px; margin: 0 auto; color: white } </style> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <div id="parent"></div> <br><br> <button onclick="insertDiv()"> Insert Div </button> <!-- Script to insert div element --> <script> function insertDiv() { $("#parent").append('<div id = "newElement">A ' + 'Computer Science portal for geeks</div>'); } </script> </body> </html> Output: Example 2: This example creates a <div> element and uses prependTo() method to append the element at the start of parent element. html <!DOCTYPE html> <html> <head> <title> Create div element using jQuery </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <style> #parent { height: 100px; width: 300px; background: green; margin: 0 auto; } #newElement { height: 40px; width: 100px; margin: 0 auto; color: white } </style> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <div id="parent"></div> <br><br> <button onclick="insertDiv()"> Insert Div </button> <script> function insertDiv() { $('<div id = "newElement">A Computer Science portal' + ' for geeks</div>').prependTo($('#parent')); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article Create a Div Element using jQuery P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JQuery jQuery-Basics Similar Reads How to create a div element in jQuery ? 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 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 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 jQuery UI Button create Event jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Button create event is used to trigger when the button element is created. This event accept a callback function that h 1 min read How to count all elements within a div using jQuery ? In this article, we will count all elements inside a div element using jQuery. To count all elements inside a div elements, we use find() method and length property. The find() method is used to find all the descendant elements of the selected element. It will traverse all the way down to the last l 1 min read Like